您的位置:首页 > 其它

正则表达式 每个单词首字母大写

2011-07-27 11:39 316 查看
using System.Text.RegularExpressions;

class RegExSample
{
static string CapText(Match m)
{
// Get the matched string.
string x = m.ToString();
// If the first char is lower case...
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 + "]");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: