正则表达式每个单词⾸字母⼤写using System.Text.RegularExpressions;
class RegExSample
{
static string CapText(Match m)
{
// Get the matched string.
string x = m.ToString();
// If the first char is
if (char.IsLower(x[0]))
{
// Capitalize it.
return char.ToUpper(x[0]) + x.Substring(1, x.Length-1);
}
return x;
}
static void Main()
{
string text = "four score and seven years ago";
System.Console.WriteLine("text=[" + text + "]");
string result = Regex.Replace(text, @"\w+",
new MatchEvaluator(RegExSample.CapText));
正则化英文System.Console.WriteLine("result=[" + result + "]");
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。