我在这做错了什么?我希望用户名在输出中显示为正确但我无法弄明白.
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();
Run Code Online (Sandbox Code Playgroud)
我已经测试了以下全部大写单词,它的工作原理如下:
string proper = "TEST STRING";
CultureInfo properCase = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo currentInfo = properCase.TextInfo;
proper = currentInfo.ToTitleCase(currentInfo.ToLower(proper));
// proper = "Test String"
Run Code Online (Sandbox Code Playgroud)
所以 - 在调用之前将字符串更改为小写ToTitleCase.
的MSDN文档中并说,一个字符串,它是所有大写(例如,首字母缩写)将不被转换,并在后提供的示例代码证实了这一.
| 归档时间: |
|
| 查看次数: |
5827 次 |
| 最近记录: |