Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

capitalize first char of string

Status
Not open for further replies.

jamert

Programmer
Dec 9, 2007
80
CA
Hi i've scoured the net and found examples of how to capitalize the first character of a string or to use "ToTitleCase". Capitalize first character reulted in a things like taking the first character.toUpper and putting the string back together; some involved regex ,others not. I'm trying to do this the "ToTitleCase" way, but i can't seem to get it to work without: CultureInfo
eg:
CultureInfo.CurrentCulture.TextInfo.ToTitleCase(string);

reading on the CultureInfo.CurrentCulture Property resulted in negative security comments. Wondering what the best approach for this? any comments...
 
what's wrong with this?
Code:
public function MyTitleCase(string input)
{
   if(string.IsNullOrEmpty(input)) return string.Empty;
   return input[0].ToUpperCase + input.SubString(1, input.Length - 2);
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Jason -
public function MyTitleCase(string input)

Is that something new in VS2008, or have you been doing too much VB work lately [lol]



[small]----signature below----[/small]
I'm pushing an elephant up the stairs

My Crummy Web Page
 
i feel so ashamed [tongue]
Code:
public string MyTitleCase(string input)
{
   if(string.IsNullOrEmpty(input)) return string.Empty;
   return input[0].ToUpperCase + input.SubString(1, input.Length - 2);
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
That's more like it!

Week's almost over, hang in there :-D

[small]----signature below----[/small]
I'm pushing an elephant up the stairs

My Crummy Web Page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top