如何按字母数字对数字进行排序
输入:
SHC 111U、SHB 22x、SHA 5555G
所需输出:
SHB 22X、SHC 111U、SHA 5555G
我只需对停车区中的车辆编号
进行排序,而不是前缀和后缀字母
Input:
SHC 111U,SHB 22x,, SHA 5555G
Needed output:
SHB 22X, SHC 111U, SHA 5555G
I have to sort only Vehicle no
in the Parking Area not prefix and suffix letter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
出色的、优化良好的开源解决方案,位于 http://dotnetperls.com/alphanumeric-sorting
Fantastic, well-optimized open source solution at http://dotnetperls.com/alphanumeric-sorting
没有任何内置功能可以执行此操作,但您可以通过首先提取数字并基于此进行排序来完成此操作。例如:
这是未经测试的(并且可能在不修改的情况下甚至无法编译),没有错误检查,并且可能不是世界上最快的方法,但应该给您一个想法。
There is nothing built-in to do this, but you can do it by first extracting the numbers and sorting based on that. For example:
This is untested (and probably won't even compile without modification), has no error checking, and probably isn't the fastest method in the world, but should give you an idea.
如果可能有没有号码的车牌,那么您应该检查一下。
如果这是绝对不可能的,并且世界末日会在没有数字的盘子出现之前到来,那么这个缩写形式将起作用:
If it is possible to have a plate without a number then you should check for that.
If it is absolutely impossible and the end of the world would come before there could ever be a plate without numbers then this shortened form will work:
执行此操作的一个好方法是执行类似的操作
编写一个正则表达式以仅匹配名称的数字部分,将其放入配对整数值的集合中,第一个是从字符串中提取的数字,第二个是从字符串中提取的数字是原始列表中数字的索引。然后对第二个列表进行排序,然后使用集合中的第二个数字对第一个列表重新排序。
A good way to do this would be to do something like this
Write a regular expression to match just the numeric portion of the name, put that in a collection of paired integer values, the first being the number you pulled from your string and the second being the index of the number in the original list. Then sort the second list, and then reorder the first list using the second number in your collection.
使用接受 IComparer< 的排序方法/a> 对象并向其传递您的车辆号码集合。您需要定义一个实现 IComparer 的自定义类。在该类的 Compare 方法中,您可以编写代码来比较两个车辆编号。您可能应该使用正则表达式来提取车辆号码的数字部分。
Use a Sort method that accepts an IComparer object and pass it your collection of vehicle numbers. You will need to define a custom class that implements IComparer. In the Compare method of that class you can write code to compare the two vehicle numbers. You should probably use a regex for extracting the numerical part of the vehicle number.