Dum*_*pen 2 c# string split join getfiles
我有以下代码:
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;
}
Run Code Online (Sandbox Code Playgroud)
其中一个用作搜索特定文件类型列表的方法,但当前代码的问题是String.Join不将分隔符放在第一个项目(这是有意义的).
所以我的supportedFileTypes结果是:
jpg,*.pdf,*.doc,*.docx,*.xlsx
Run Code Online (Sandbox Code Playgroud)
但我希望它是:
*.jpg,*.pdf,*.doc,*.docx,*.xlsx
Run Code Online (Sandbox Code Playgroud)
我可以以一种非常干净的方式做到这一点吗?
注意:我无法改变内容 supportedImageFormats
string newStr = string.Join(",", supportedImageFormats.Split(',')
.Select(r => "*." + r));
Run Code Online (Sandbox Code Playgroud)
输出: Console.WriteLine(newStr);
*.jpg,*.pdf,*.doc,*.docx,*.xlsx
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
232 次 |
| 最近记录: |