I should note -- this function assumes that one will only ever pass in a single lower/UpperCamelCase word (i.e. no spaces, etc).
--
Greg Collins [InfoPath MVP]
Please visit:
http://www.InfoPathDev.com
"Greg Collins [InfoPath MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message news:#7**************@TK2MSFTNGP15.phx.gbl...
Thanks. I knew that had to be something fairly simple.
So which is faster -- to use the Match Evaluator, or to just blindly convert the first character ToUpper() before running the more simple Regex?
public string CamelToTitleCase(string Text)
{
Text = Text.Substring(0, 1).ToUpper() + Text.Substring(1);
return Regex.Replace(Text, @"(\B[A-Z])", @" $1");
}
--
Greg Collins [InfoPath MVP]
Please visit:
http://www.InfoPathDev.com
"Ludovic SOEUR" <Lu***********@hotmail.com> wrote in message news:uv**************@TK2MSFTNGP14.phx.gbl...
To convert from UpperCamelCase to Title Case, use this line :
Regex.Replace("UpperCamelCase",@"(\B[A-Z])",@" $1");
To convert from both lowerCamelCase and UpperCamelCase to Title Case, use
MatchEvaluator :
public string toTitleCase(Match m) {
char c=m.Captures[0].Value[0];
return ((c>='a')&&(c<='z'))?Char.ToUpper(c).ToString():" "+c;
}
and change a little your regex with this line :
Regex.Replace("UpperCamelCase or lowerCamelCase",@"(\b[a-z]|\B[A-Z])",new
MatchEvaluator(toTitleCase));
Hope it helps,
Ludovic SOEUR.
"Greg Collins [InfoPath MVP]" <Greg.Collins_AT_InfoPathDev.com> a écrit dans
le message de news:%2***************@TK2MSFTNGP12.phx.gbl...
I couldn't find anything in my searches... I'm wondering if there's a Regex
(with or without additional C# code) that can convert a either
"lowerCamelCase" or "UpperCamelCase" into a proper "Title Case" (with
spaces).
Thanx!
--
Greg Collins [InfoPath MVP]
Please visit:
http://www.InfoPathDev.com