欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)簡(jiǎn)單過(guò)濾非法字符實(shí)例

 更新時(shí)間:2015年11月25日 11:35:33   作者:一只小青蛙  
這篇文章主要介紹了C#實(shí)現(xiàn)簡(jiǎn)單過(guò)濾非法字符的方法,涉及C#針對(duì)字符串遍歷與判斷的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了C#實(shí)現(xiàn)簡(jiǎn)單過(guò)濾非法字符的方法。分享給大家供大家參考,具體如下:

#region 過(guò)濾非法字符
public static string encoding(string src)
{
  if (src == null)
   return "";
  StringBuilder result = new StringBuilder();
  if (src != null)
  {
   src = src.Trim();
   for (int pos = 0; pos < src.Length; pos++)
   {
    switch (src[pos])
    {
     case '\"': result.Append("''"); break;
     case '<': result.Append("<"); break;
     case '>': result.Append(">"); break;
     case '\'': result.Append("&apos;"); break;
     case '&': result.Append("&"); break;
     case '%': result.Append("&pc;"); break;
     case '_': result.Append("&ul;"); break;
     case '#': result.Append("&shap;"); break;
     case '?': result.Append("&ques;"); break;
     default: result.Append(src[pos]); break;
    }
   }
  }
  return result.ToString();
}
#endregion

希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論