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 + "]"); } }