.net – .ToTitleCase不适用于所有大写字符串

前端之家收集整理的这篇文章主要介绍了.net – .ToTitleCase不适用于所有大写字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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());
原文链接:https://www.f2er.com/aspnet/250289.html

猜你在找的asp.Net相关文章