/// <summary> /// 去除特殊字符 /// </summary> /// <param name="text"></param> /// <returns></returns> public static string MakeValidFileName(string text) { StringBuilder str = new StringBuilder(); var invalidFileNameChars = Path.GetInvalidFileNameChars(); foreach (var c in text) { if (!invalidFileNameChars.Contains(c)) { str.Append(c); } } return str.ToString(); }标签:string,文件名,text,str,去除,var,特殊符号 From: https://www.cnblogs.com/0624zfz/p/16804999.html