我在这里做错了什么?我希望用户名在输出中显示为正确的大小写,但我无法弄清楚。

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

最佳答案

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

string proper = "TEST STRING";
CultureInfo properCase = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo currentInfo = properCase.TextInfo;
proper = currentInfo.ToTitleCase(currentInfo.ToLower(proper));
// proper = "Test String"

所以 - 在调用 ToTitleCase 之前将字符串更改为小写。

MSDN 文档确实说不会转换全大写的字符串(例如首字母缩写词),并且帖子中提供的示例代码证实了这一点。

关于c# - 适当的案例标题案例问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2844248/

10-08 22:54