将逗号分隔的字符串转换为GetFiles SearchPattern

转储

我有以下代码:

private string[] FindExistingDocuments()
{
    string supportedImageFormats = "jpg,pdf,doc,docx,xlsx";

    DirectoryInfo documentPath = new DirectoryInfo("...");

    string supportedFileTypes = String.Join(",*.", supportedImageFormats.Split(','));
    string[] files = Directory.GetFiles(documentPath.FullName, supportedFileTypes, SearchOption.AllDirectories);

    return files;
}

哪一种功能是搜索文件类型的特定列表的一种方法,但是当前代码的问题是String.Join没有将分隔符放在第一项(这很有意义)。

所以我的supportedFileTypes结果是:

jpg,*.pdf,*.doc,*.docx,*.xlsx

但我希望它是:

*.jpg,*.pdf,*.doc,*.docx,*.xlsx

我可以以某种非常干净的方式使它变得干净吗?

注意:我无法更改以下内容 supportedImageFormats

哈比卜
string newStr = string.Join(",", supportedImageFormats.Split(',')
                                     .Select(r => "*." + r));

输出: Console.WriteLine(newStr);

*.jpg,*.pdf,*.doc,*.docx,*.xlsx

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Directory.GetFiles方法上的searchPattern逻辑

Directory.GetFiles searchPattern与文档不一致

C将逗号分隔的字符串转换为数组

将int []转换为逗号分隔的字符串

将逗号分隔的字符串转换为HashSet

将逗号分隔的字符串转换为列表

将数组转换为逗号分隔的字符串

将逗号分隔的字符串转换为列表

将数组转换为逗号分隔的字符串

Python:将元组转换为逗号分隔的字符串

将Ints数组转换为逗号分隔的字符串

将逗号分隔的字符串转换为 JSON

将逗号分隔的字符串转换为数组

将逗号分隔的字符串转换为日期时间

System.IO.Directory.GetFiles的多个文件扩展名searchPattern

Helm 将图表标签多行字符串转换为逗号分隔的字符串

通过附加串联将字符串数组转换为逗号分隔的字符串

将字符串或列表的映射转换为值的字符串或逗号分隔的值

将逗号分隔的字符串转换为最后一个带有逗号的列表

PHP将逗号分隔的字符串转换为点或符号分隔的值,以存储在MySql中

如何将逗号分隔的字符串转换为对象内的分隔数组?

将字符串列表转换为逗号分隔的字符串,而不重复

如何将逗号分隔的字符串或/ n分隔的字符串转换为jquery中的列表?

在Java中将String []转换为逗号分隔的字符串

将以逗号分隔的键值对字符串转换为字典

快速将逗号分隔的字符串转换为NSMutableArray

在Java中将逗号分隔的字符串转换为json

如何将逗号分隔的字符串字段转换为 MongoDB 中的对象数组?

如何将逗号分隔的字符串字段转换为 MongoDB 中的数组?