gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:22:59 35 4
gpt4 key购买 nike

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

关于.net - .ToTitleCase 不适用于所有大写字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7043391/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com