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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....