.ToTitleCase not working on all upper case string

前端 未结 3 1059
旧时难觅i
旧时难觅i 2021-02-19 02:26
Public Function TitleCase(ByVal strIn As String)
      Dim result As String = \"\"
      Dim culture As New CultureInfo(\"en\", False)
      Dim tInfo As TextInfo = cult         


        
3条回答
  •  轮回少年
    2021-02-19 02:54

    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());
    

提交回复
热议问题