Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.ToTitleCase not working on all upper case string

Public Function TitleCase(ByVal strIn As String)
      Dim result As String = ""
      Dim culture As New CultureInfo("en", False)
      Dim tInfo As TextInfo = culture.TextInfo()
      result = tInfo.ToTitleCase(strIn)
      Return result
 End Function

If I input "TEST" into the function above. The output is "TEST". Ideally it would output "Test"

I also tried the code snippets from this post to no avail: Use of ToTitleCase

like image 720
s15199d Avatar asked Aug 12 '11 16:08

s15199d


1 Answers

If memory serves, ToTitleCase() never seemed to work for all capitalized strings. It basically requires you to convert the string to lowercase prior to processing.

From the MSDN:

Generally, title casing converts the first character of a word to uppercase and the rest of the characters to lowercase. However, this method does not currently provide proper casing to convert a word that is entirely uppercase, such as an acronym.

Workaround Usage (in C#):

string yourString = "TEST";

TextInfo formatter = new CultureInfo("en-US", false).TextInfo;    
formatter.ToTitleCase(yourString.ToLower());
like image 141
Rion Williams Avatar answered Sep 19 '22 20:09

Rion Williams