The VBScript Regex.Replace method only allows to replace a specified string (or pattern) by another specified string.
The .NET Regex.Replace method is overloaded (means many definitions with different arguments) and some allows to use a MatchEvaluator delegate as argument (a method defined with requiered argument(s) and return value).
Since NET 3.0 version delegates can be specified as 'lambda expressions' which allows more concise (and cryptic ?) code:
x => x.Value.ToUpper() (where x is a Match object: the MatchEvaluator argument).
A 'more traditionnal' way should have been to define the delegate as an external function:
public string TitleCase(string s)
{
return Regex.Replace(s.ToLower(), "(^[a-z]|\\s[a-z])", MatchToUpper); }));
}
private string MatchToUpper(Match m)
{
return m.Value.ToUpper();
}
Or using an 'anonymous method' (more like the lambda LISP function):
private static string TitleCase(string s)
{
return Regex.Replace(s.ToLower(), "(^[a-z]|\\s[a-z])", delegate(Match m) { return m.Value.ToUpper(); });
}
Maybe it's not the right forum for this (Please CAB, don't cry...)