using System.Text.RegularExpressions;
class Test {
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(Test.CapText));
System.Console.WriteLine("result=[" + result + "]");
}
}