What am i doing wrong here? I want the users name to be shown in the output as propercase but I cant figure it out.
string proper = this.xTripNameTextBox.Text;
CultureInfo properCase = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo currentInfo = properCase.TextInfo;
proper = currentInfo.ToTitleCase(proper);
this.xTripOutputLabel.Text = proper + Environment.NewLine + "The total gallons you would use: " + Output.ToString("0") + Environment.NewLine + "Total amount it will cost you: " + Coutput.ToString("C") + Environment.NewLine +" Your customer number is " + rnd1.Next(1, 1000).ToString();
I have tested the following on an all upper case word at it works:
string proper = "TEST STRING";
CultureInfo properCase = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo currentInfo = properCase.TextInfo;
proper = currentInfo.ToTitleCase(currentInfo.ToLower(proper));
// proper = "Test String"
So - change the string to lower case before calling ToTitleCase
.
The MSDN documentation does say that a string that is all upper case (such as an acronym) will not be converted and the sample code provided in the post corroborates this.
That's according to spec, quote from the doc: However, this method does not currently provide proper casing to convert a word that is entirely uppercase
http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx
Without testing I'd guess that you could do it by first making it LowerCase
and then TitleCase
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With