Reputation: 16219
//for e.g.
string s="this is example";
//how can i make output like "This Is Example"
using too simple code in c#??
Upvotes: 6
Views: 4440
Reputation: 1
Try using the below code
Console.WriteLine(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(str));
Upvotes: 0
Reputation: 16768
What you're describing is sometimes called ProperCase, or in C# case, TitleCase. It might seem like overkill, but as far as I know it takes some 'cultural' localization information. Luckily you can just default to the one currently in use.
CultureInfo c = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = c.TextInfo;
String newString = textInfo.ToTitleCase(oldString);
Of course in practice you'll probably want to put it all together like Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase
, but it can't hurt to see what all that crap means.
http://support.microsoft.com/kb/312890
Upvotes: 7
Reputation: 82913
Try this.
String s = "this is example";
Console.WriteLine(Thread.CurrentCulture.TextInfo.ToTitleCase(s));
Upvotes: 10