按字母顺序对字符串中的数字进行排序
我们有一个标题列表,其中一些以数字开头(例如 5 Ways to Make Widgets)。我们希望将其排序为“五种方式......”而不更改标题。我们知道有些电影场所会这样做,但我在网上找不到有关如何操作的信息。有什么想法吗?
We have a list of titles, some of which start with numbers (e.g. 5 Ways to Make Widgets). We would like to sort this as if it were "Five Ways..." without changing the title. We know that some movie places do this, but I can't find info online on how to do it. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
存储原始标题和拼写的标题。
另请参阅:将整数转换为书面数字
Store both the original title and the spelled-out title.
See also: Convert integers to written numbers
在计算机科学中,学习编程时,有时会有一个将数字转换为文本的作业。喜欢:
在这种情况下,这可能是您需要的。
这是一项微不足道的作业,但却是一个很好的教训。
In Computer Science, when learning programming, sometimes there is an assignment to convert numbers to text. Like:
This is probably something you'll need in this case.
It is a trivial assignment but it is a good lesson.
创建自定义比较器请参阅 http://support.microsoft.com/kb/320727。
本质上,您想要做的是测试第一个字符是否是数字。如果它不只是恢复为标准字符串比较,如果是,那么您可以进行一些额外的处理来获取数字的文本版本。
一旦你拥有了这种最排序算法,就可以让你传递比较器。
Create a custom comparer see http://support.microsoft.com/kb/320727.
Essentially what you want to do is test if the first character is a number. If it isn't just revert to a standard string compare, if it is then you can do some additional processing to get a textual version of the number.
Once you have this most sort algorithms will allow you to pass the comparer in.
扩展其他人的建议:
此代码将“101 dalmations”转换为“oneohone dalmations”,将“12angry men”转换为“onetwoangry men”。可以构建更完整的解决方案,也许来自Wedge 针对略有不同的问题的解决方案。我还没有测试过该代码,它也不是设计来处理数字后面的字符串的,但这可能是一个好的开始。
To expand on other people's suggestions:
This code turns "101 dalmations" into "oneohone dalmations" and "12 angry men" into "onetwo angry men". A more complete solution could be built, perhaps from Wedge's solution to a slightly different problem. I haven't tested that code, and it isn't designed to handle the string after the digits, but it's probably a good start.