C#基础-replace()过滤非法字符

 1 string FilterfileName(string strName)
 2 {         
 3    string result=string.Empty ;
 4    if (string.IsNullOrWhiteSpace(strName))
 5    {
 6       //do something
 7    }
 8    else
 9    {
10     result = strName.Replace("\", "_").Replace("/", "_").Replace(":", "_")
11              .Replace("*","_").Replace("?","_").Replace("<","_")
12              .Replace(">","_").Replace("|","_").Replace(""","_");
13    } 
14    return result;       
15 }
原文地址:https://www.cnblogs.com/lovecsharp094/p/5427095.html