so basically if i want to transform a name from
stephen smith
to
Stephen Smith
i can easily do it with c
A slight extension on the answer offered by Pedro:
Regex.Replace(Name, @"(?:(M|m)(c)|(\b))([a-z])", delegate(Match m) {
return String.Concat(m.Groups[1].Value.ToUpper(), m.Groups[2].Value, m.Groups[3].Value, m.Groups[4].Value.ToUpper());
});
This will correctly capitalize McNames in addition to title case. eg "simon mcguinnis" --> "Simon McGuinnis"
If it matches "Mc" or "mc" the groups 1 and 2 contain "m" and "c" and group 3 is empty.
All 4 groups, empty or otherwise, are concatenated to generate the return string.