I admit regex is a strange world and I have not been able to really get my head wraped around it. But I have this problem that I believe belongs in the regex world.
i would like to change last names like “o’brian” to “O’Brian” or “macdonald” to “MacDonald” or “who-knew” to “Who-Knew” or “who knew” to “Who Knew”
so far all I have is ….
setCaps("o'brian");
string setCaps(string s)
{
string result = Regex.Replace(s, @"\b[a-z]['a-z]\w+", delegate(Match match)
{
string ch = match.ToString();
return char.ToUpper(ch[0]) + ch.Substring(1);
});
return result;
}
Thanks
Not actually sure this is possible for your Mac…. For example, while macdonald should be MacDonald, Mrs Macey really doesn’t want to be Mrs MacEy. And what if its company names? Smith’s Machinery, doesn’t want to be Smith’s MacHinery!
The “O” prefix could be problematic also. Consider Mr O’Pera, or Mrs O’Pal!
The best thing to do with Mac and Mc prefixes is to hold an exception list, which you refer back to. There are only a finite number of these style names!
The following should help start:
http://dgmweb.net/genealogy/FGS/Indices/EveryNameIndex-Mc.shtml