我有以下代码:
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] 删除。
我来说两句