DDK <dd*******@hotmail.com> wrote:
What is the best way to capitalize the first letter of a string?
As well as the previous responses, you may wish to consider the
following if you're doing this a lot - it avoids creating an extra
string unnecessarily:
static string UpperCaseFirstLetter (string original)
{
if (original.Length==0)
{
return original;
}
char originalFirst = original[0];
char upperFirst = char.ToUpper(originalFirst);
if (originalFirst==upperFirst)
{
return original;
}
return upperFirst + original.Substring(1);
}
Note that that will perform the upper casing in the current culture -
you could write another version which specified which culture to use
(and used it in the call to char.ToUpper).
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too