有没有人有一个良好的正确的案例算法有没有人、算法、有一个、良好

由网友(老板、给我瓶敌敌畏)分享简介:有没有人有一个值得信赖的适当的案件或PCase算法(类似于用Ucase或上)?我在寻找的东西取一个值,例如乔治BURDELL或乔治burdell,并将其到乔治Burdell。Does anyone have a trusted Proper Case or PCase algorithm (similar to a...

有没有人有一个值得信赖的适当的案件或PCase算法(类似于用Ucase或上)?我在寻找的东西取一个值,例如乔治BURDELL乔治burdell,并将其到乔治Burdell

Does anyone have a trusted Proper Case or PCase algorithm (similar to a UCase or Upper)? I'm looking for something that takes a value such as "GEORGE BURDELL" or "george burdell" and turns it into "George Burdell".

我有一个简单的处理简单的案件。理想的做法是有什么事情,能处理事情,如O'REILLY,并把它变成奥赖利,但我知道这是强硬的。

I have a simple one that handles the simple cases. The ideal would be to have something that can handle things such as "O'REILLY" and turn it into "O'Reilly", but I know that is tougher.

我主要集中在英语,如果它简化了的东西。

I am mainly focused on the English language if that simplifies things.

更新:我使用C#作为语言,但我几乎可以从任何转换(假设像功能存在)

UPDATE: I'm using C# as the language, but I can convert from almost anything (assuming like functionality exists).

我同意麦当劳scneario是一个艰难的一个。我的意思是说,随着我的O'Reilly的例子,但在原来的职位都没有。

I agree that the McDonald's scneario is a tough one. I meant to mention that along with my O'Reilly example, but did not in the original post.

推荐答案

除非我误解你的问题,我不认为你需要推出自己的TextInfo类能为你做。

Unless I've misunderstood your question I don't think you need to roll your own, the TextInfo class can do it for you.

using System.Globalization;

CultureInfo.InvariantCulture.TextInfo.ToTitleCase("GeOrGE bUrdEll")

将返回乔治Burdell,你可以用你自己的文化,如果有涉及到一些特殊的规则。

Will return "George Burdell. And you can use your own culture if there's some special rules involved.

更新: 迈克尔(在评论这个回答)指出,如果输入的是全部大写,因为该方法假定它是一个缩写,这是不行的。天真的解决方法是,以.ToLower()文本提交给ToTitleCase之前。

Update: Michael (in a comment to this answer) pointed out that this will not work if the input is all caps since the method will assume that it is an acronym. The naive workaround for this is to .ToLower() the text before submitting it to ToTitleCase.

阅读全文

相关推荐

最新文章