谢谢!!
6 个解决方案
#1
沙发 先抢
#2
/['\t]/g,'').replace(/\s*/g, '' 试试看这个
#3
1、直接替换掉这些标点或是特殊字符
string yourStr = ............;
string resutlStr = Regex.Replace(yourStr, @ "[,。@\$] ", " ");
把想替换掉的字符主在[]里,有些特殊字符需要用“\”转义
.$ ^ { [ ( | ) * + ? \
2、如果想替换掉的字符太多,一一列举比较麻烦,那就保留你想保留的,比如字母,数字,汉字,空白格式字符等
string yourStr = ............;
string resutlStr = Regex.Replace(yourStr, @ "[^a-zA-Z0-9\u4e00-\u9fa5\s] ", " ");
把想保留的放在[]中
#4
value=value.replace(/['\t]/g,'').replace(/\s*/g, '')
#5
string input = "This is text with far too much " + "whitespace.";
string pattern = "\\s+";
string replacement = "";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("Replacement String: {0}", result);
msdn里修改的,建议你看看
http://msdn.microsoft.com/zh-cn/library/system.text.regularexpressions.regex.replace.aspx
http://msdn.microsoft.com/zh-cn/library/xwewhkd1.aspx
string pattern = "\\s+";
string replacement = "";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("Replacement String: {0}", result);
msdn里修改的,建议你看看
http://msdn.microsoft.com/zh-cn/library/system.text.regularexpressions.regex.replace.aspx
http://msdn.microsoft.com/zh-cn/library/xwewhkd1.aspx
#6
str = Regex.Replace(str, @"\s", "");
or
str = str.Replace(" ", "");
#1
沙发 先抢
#2
/['\t]/g,'').replace(/\s*/g, '' 试试看这个
#3
1、直接替换掉这些标点或是特殊字符
string yourStr = ............;
string resutlStr = Regex.Replace(yourStr, @ "[,。@\$] ", " ");
把想替换掉的字符主在[]里,有些特殊字符需要用“\”转义
.$ ^ { [ ( | ) * + ? \
2、如果想替换掉的字符太多,一一列举比较麻烦,那就保留你想保留的,比如字母,数字,汉字,空白格式字符等
string yourStr = ............;
string resutlStr = Regex.Replace(yourStr, @ "[^a-zA-Z0-9\u4e00-\u9fa5\s] ", " ");
把想保留的放在[]中
#4
value=value.replace(/['\t]/g,'').replace(/\s*/g, '')
#5
string input = "This is text with far too much " + "whitespace.";
string pattern = "\\s+";
string replacement = "";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("Replacement String: {0}", result);
msdn里修改的,建议你看看
http://msdn.microsoft.com/zh-cn/library/system.text.regularexpressions.regex.replace.aspx
http://msdn.microsoft.com/zh-cn/library/xwewhkd1.aspx
string pattern = "\\s+";
string replacement = "";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("Replacement String: {0}", result);
msdn里修改的,建议你看看
http://msdn.microsoft.com/zh-cn/library/system.text.regularexpressions.regex.replace.aspx
http://msdn.microsoft.com/zh-cn/library/xwewhkd1.aspx
#6
str = Regex.Replace(str, @"\s", "");
or
str = str.Replace(" ", "");