C# 适当案例标题案例问题

C# 适当案例标题案例问题,c#,C#,我做错了什么?我希望用户名在输出中显示为propercase,但我无法理解 string proper = this.xTripNameTextBox.Text; CultureInfo properCase = System.Threading.Thread.CurrentThread.CurrentCulture; TextInfo currentInfo = properCase.TextInfo; proper = currentInfo.ToTitleCase(proper); th

我做错了什么?我希望用户名在输出中显示为propercase,但我无法理解

string proper = this.xTripNameTextBox.Text;
CultureInfo properCase = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo currentInfo = properCase.TextInfo;
proper = currentInfo.ToTitleCase(proper);

this.xTripOutputLabel.Text = proper +  Environment.NewLine + "The total gallons you would use: " + Output.ToString("0") + Environment.NewLine + "Total amount it will cost you: " + Coutput.ToString("C") + Environment.NewLine +" Your customer number is " + rnd1.Next(1, 1000).ToString(); 

似乎是对的,我正在使用

return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text);
它正在工作

尝试强制其他区域性信息

另见


这是根据规范,引用文档:但是,这种方法目前没有提供正确的大小写来转换完全大写的单词


如果不进行测试,我想您可以先将其设置为
小写
,然后将其设置为
标题框

我已经在一个全大写单词上测试了以下内容:

string proper = "TEST STRING";
CultureInfo properCase = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo currentInfo = properCase.TextInfo;
proper = currentInfo.ToTitleCase(currentInfo.ToLower(proper));
// proper = "Test String"
So-在调用
ToTitleCase
之前,将字符串改为小写


文档中确实指出,全大写的字符串(如首字母缩略词)将不会被转换,文章中提供的示例代码证实了这一点。

您能告诉我们您得到了什么以及您期望得到什么吗?当用户输入“JOHN DOE”时,我得到了“JOHN DOE”,应该将其转换为正确的大小写“JOHN DOE”,但我不知道我做错了什么,这就是问题所在,使用ToLower先将字符串转换为小写,然后标题的大小写就可以了。可能的重复请看一看@