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
如果我在上面的函数中输入“TEST”输出为“TEST”.理想情况下会输出“测试”
我也试过这个帖子的代码片段没有用:Use of ToTitleCase
解决方法
如果记忆服务,ToTitleCase()似乎并不适用于所有大写字母串.它基本上要求您在处理之前将字符串转换为小写.
从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.
解决方法使用(在C#中):
string yourString = "TEST"; TextInfo formatter = new CultureInfo("en-US",false).TextInfo; formatter.ToTitleCase(yourString.ToLower());