正则表达式 :这段代码什么意思啊?

来源:百度知道 编辑:UC知道 时间:2024/06/15 14:47:10
public static string InputText(string text)
{
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;

//if (text.Length > maxLength)
// text = text.Substring(0, maxLength);
text = Regex.Replace(text, "[\\s]{2,}", " "); //two or more spaces
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //<br>
text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); // 
text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); //any other tags
text = text.Replace("'", "''");
return text;

}

public static string InputText(string text)
{
text = text.Trim(); //去空格
if (string.IsNullOrEmpty(text)) //如果是空字符串
return string.Empty; //返回空的..囧

//if (text.Length > maxLength)
// text = text.Substring(0, maxLength);
text = Regex.Replace(text, "[\\s]{2,}", " "); //把2个以上的空格变一个
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //<br> // <br> 和 <p> (网页中换行)替换成 换行符
text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); // 把& nbsp;(网页中的空格) 替换成 空格
text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); //其他的<...>弄掉
text = text.Replace("'", "''"); //单引号替换成双引号
return text; //返回

}

英语 确实学的不好 帮不上你喽

去运行一下啊就知道了啊!

字符串替换
\s\s或\s\s\s或更多替换为空