using System.Text.RegularExpressions;//正则表达式类
class RegExSample
{
staticstring CapText(Match m) // 实例一个mach类对象 m
{
// Get the matched string.string x = m.ToString(); //将符合正则表达式的字符串->x
// If the first char is lower case...if (char.IsLower(x[0])) //小写转换为大写
{
// Capitalize it.returnchar.ToUpper(x[0]) + x.Substring(1, x.Length-1);
}
return x;
}
staticvoid Main()
{
string text = "four score and seven years ago";
System.Console.WriteLine("text=[" + text + "]"); //输出源字符串
string result = Regex.Replace(text, "s", //"s"原为@"/w+",不解.因此改为"s"测试一下语句功能 {replace()第一个参数为要修改的字符串,第二个参数为正则表达式,第三个参数为 将满足正则表达式的字符串替换的字符串}
new MatchEvaluator(RegExSample.CapText)); //将text字符串中为s的替换为new MatchEvaluator(RegExSample.CapText),即将小写"s"转换为大写"S"
System.Console.WriteLine("result=[" + result + "]");
}
}
///一下引用MSDN 例子using System.Text.RegularExpressions;//正则表达式类class RegExSample { static string CapText(Match m) // 实例一个mach类对象 m { // Get the matched string. string x