Capitalizing a string using C#

I was in need of a quick way to capitalize all of the words in a string (and though to check with Google before writing my own implementation). Here is what I found:

  1. This one is built-in to .Net, but can be slow at times (and some people do not like the way that it handles capitalizations of Unicode strings)
  1. Based on Regular Expressions (2 examples found here)
  2. Some other home-baked implementations, mostly scanning through the string for whitespace, and capitalizing new words as they come up.

Am I missing anything?

Handy .net Regex app

As I am learning more about regular expressions and I want to use some in my code, I find myself in a bit of a quandry – how can I try out the regular expression that I am using to see if it does what I need it to do (with the .net flavor of Regex).

I found this very useful application (download here). It is a C# demo program for using regular expressions with the .Net framework. Source code is included.

The site also has a good .Net and general Regex reference.


Found this nifty tool to perform regular expression searches on file (and I didn’t want to pay $150 for PowerGREP). Google helped me out and led the way to baregrep. Works very fast, easy to use interface, yada yada. You can pay them $25 to get rid of the splash screen, or just use it for free. They also have a good one-page regular expression reference, in case you are in need of a little brush-up.

Update: One shortcoming that I have found is that it doesn’t handle Unicode well. The original reason why I needed this tool was so that I could generate a script from Sql Server of all of my Stored Procedures for a certain project, and then search the script for certain text. I find that in order to do this, after I have first generated the script I then need to go and save it again as ANSI (it was created in unicode). Oh well. I guess I can’t really complain too much, given the price that I paid to obtain the software.