Correct Case Title

What am I doing wrong here? I want the username displayed on the output for granted, but I can't 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(); 
+4
source share
3 answers

I tested the following on the entire upper word in it:

 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 lowercase before calling ToTitleCase .

The MSDN documentation says that a string that is uppercase (such as an acronym) will not be converted, and the sample code provided in the message confirms this.

+8
source

This is according to the specification, cited from the document: However, this method does not currently provide the proper wrapper for converting a word that is completely capitalized.

http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx

Without testing, I would suggest that you can do this by doing LowerCase first and then TitleCase .

+3
source

Looks like I'm using

 return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text); 

And it works.

Try creating other culture information.

see also

+1
source

Source: https://habr.com/ru/post/1309915/


All Articles