Ok, this is a simple one I ran across today after I was scavenging through my code trying to find a proper case converter I’d written a while back. Turns out there’s a much easier way using the TextInfo class:
public static string ProperCase(string Input)
This has the additional advantage that it is culture aware since some countries don’t upper and lower the same way we do.
Who’d thunk this is available? FWIW, various Text formatting commands don’t live on the string class itself. I often use RegEx (for replacements especially), StringBuilder and now TextInfo for many string tasks. It’d sure would be nice if some of this was better cross referenced in the docs.
Apparently I’m not the only one who hasn’t found this one – I found at least 10 different snippets/articles that do this manually as well. This once again shows that knowing the BCL is what it’s all about – it’s probably in there if you can only find it <g>.
Other Posts you might also like