读书人

请教怎么用正则表达式去 空格和括号

发布时间: 2011-12-19 23:23:36 作者: rapoo

请问如何用正则表达式去 空格和括号
各位知道的大侠帮帮忙

[解决办法]
string S = " f asdf(!!!!)f a f a ";
Text = System.Text.RegularExpressions.Regex.Replace(S,
@ "[\s\(\)]+ ", " ");

[解决办法]
String a= "this is a demo(remove space) ";
a=a.Replace( "( ", " ").Replace( ") ", " ");
Regex re = new Regex(@ "\s+ ");
a = re.Replace(a, " ").Trim();
System.Console.WriteLine(a);
System.Console.Read();
[解决办法]
private void b()
{
string str = "A B (C) D ";
this.labeTxt.Text = Regex.Replace(str,@ "\s*\)*\(* ", " ") + "; " ;
}

读书人网 >C#

热点推荐