你的位置:首页 > ASP.net教程

[ASP.net教程]使用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 }