正确的案例标题案例问题

时间:2010-05-16 15:13:45

标签: c#

我在这里做错了什么?我希望用户名在输出中显示为正确但我无法弄明白。

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

3 个答案:

答案 0 :(得分:8)

我已经测试了以下所有大写单词的下列内容:

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文档确实说不会转换一个全部大写的字符串(例如首字母缩略词),并且帖子中提供的示例代码证实了这一点。

答案 1 :(得分:3)

这是根据规范,引用文档:然而,这种方法目前不提供适当的套管来转换完全大写的单词

http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx

如果不进行测试,我猜您可以首先制作LowerCase然后TitleCase

答案 2 :(得分:1)

似乎没错,我正在使用

return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text);

它正在发挥作用。

尝试强制使用其他文化信息。

另见