C# 去除文件非法字符名

mac2022-06-30  26

 

string resultFileName = MD5Encrypt(NavigateUrl).Replace("=",string.Empty) + ".txt"; string newFilename = string.Empty; //StringBuilder rBuilder = new StringBuilder(resultFileName); //foreach (char rInvalidChar in Path.GetInvalidFileNameChars()) //{ // rBuilder.Replace(rInvalidChar.ToString(), string.Empty); //} 或者使用linq中的Aggregate var invalidFileName = Path.GetInvalidFileNameChars(); newFilename = invalidFileName.Aggregate(resultFileName, (o, r) => (o.Replace(r.ToString(),string.Empty)));

  

转载于:https://www.cnblogs.com/c-x-a/p/7792983.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)