抱歉,如果它们对C#Asp.Net不太实用,我希望让我明白我有这种情况
string content = ClearHTMLTags(HttpUtility.HtmlDecode(e.Body)); content=content.Replace("\r\n", ""); content=content.Trim(); ((Post)sender).Description = content + "...";
我会确保字符串不包含内容或空格(Trim),并且没有回车符换行,我使用上面插入的代码但它不能很好地工作
有什么建议??
非常感谢法布里
您可以使用此正则表达式删除所有空格
content = Regex.Replace(content, @"\s+", string.Empty);
什么是MSDN的空白字符.
你错误地Trim
删除了空格,事实上它只是在字符串的开头和结尾删除空格.如果你想要替换所有空格和carige返回使用我的正则表达式.
这应该做到这一点
String text = @"hdjhsjhsdcj/sjksdc\t\r\n asdf"; string[] charactersToReplace = new string[] { @"\t", @"\n", @"\r", " " }; foreach (string s in charactersToReplace) { text = text.Replace(s, ""); }