我在这里做错了什么?我希望用户名在输出中以大小写的形式显示,但我搞不清楚。
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(); 发布于 2010-05-16 23:27:02
我已经在it works的全大写单词上测试了以下内容:
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之前将字符串更改为小写。
MSDN文档确实指出,全大写的字符串(如首字母缩写词)不会被转换,文章中提供的示例代码证实了这一点。
发布于 2010-05-16 23:25:40
这是根据规范,引用自文档:然而,此方法目前没有提供适当的大小写来转换完全大写的单词
http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx
在不测试的情况下,我猜您可以先将其设为LowerCase,然后将其设为TitleCase。
发布于 2010-05-16 23:20:49
看起来是对的,我正在使用
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text);而且它起作用了。
尝试强制另一个区域性信息。
另请参阅
https://stackoverflow.com/questions/2844248
复制相似问题