为什么我的ToTitleCase代码不起作用? [英] Why is my ToTitleCase code not working?

查看:83
本文介绍了为什么我的ToTitleCase代码不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将像ARGO这样的字符串转换为Argo和LIONEL BARRYMORE转换为Lionel Barrymore



我有这个代码:< br $> b $ b

I want to convert strings like "ARGO" to "Argo" and "LIONEL BARRYMORE" to "Lionel Barrymore"

I've got this code:

private string rightCase(string goofyStr)
{
    CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
    TextInfo textInfo = cultureInfo.TextInfo;
    return textInfo.ToTitleCase(goofyStr);
}





...我在这里得到的表格(http://support.microsoft.com / kb / 312890 / en-us)我这样称呼:





...which I got form here (http://support.microsoft.com/kb/312890/en-us) and which I call like so:

return string.Format("{0},{1},{2},", rightCase(category), rightCase(film), rightCase(actor));





...但它不起作用(ARGO未经更换,ARGO等等。)



我做错了什么?



...but it doesn't work ("ARGO" is returned unchaned, as "ARGO" etc.)

What am I doing wrong?

推荐答案

你可以尝试类似的东西 -

You can try something like -
CultureInfo.CurrentCulture.TextInfo.ToTitleCase("ARGO")


// Creates a TextInfo based on the "en-US" culture.
      

  private string rightCase(string goofyStr)
    {
       TextInfo myTI = new CultureInfo("en-US",false).TextInfo;
       return myTI.ToTitleCase(goofyStr);
    }


ToTitleCase方法提供了一种任意的套管行为,这种行为在语言上不一定正确。语言上正确的解决方案需要额外的规则,并且当前算法更简单,更快速。我们保留在未来使此API变慢的权利。

The ToTitleCase method provides an arbitrary casing behavior which is not necessarily linguistically correct. A linguistically correct solution would require additional rules, and the current algorithm is somewhat simpler and faster. We reserve the right to make this API slower in the future.

因此结果是任意的,不能依赖。



您可以尝试制作字符串所有小写​​的 TextInfo.ToLower [ ^ ]在使用TextInfo.ToTitleCase [ ^ ]并查看结果。

So the result is arbitrary and cannot be relied upon.

You could try making the string all lower case with TextInfo.ToLower[^] before using TextInfo.ToTitleCase[^] and see what the result is.


这篇关于为什么我的ToTitleCase代码不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆