//for e.g.
string s="this is example";
//how can i make output 开发者_开发问答like "This Is Example"
using too simple code in c#??
Try this.
String s = "this is example";
Console.WriteLine(Thread.CurrentCulture.TextInfo.ToTitleCase(s));
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
Try using the below code
Console.WriteLine(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(str));
精彩评论