带数值排序字符串列表 [英] Sort String list with Numeric Values

查看:162
本文介绍了带数值排序字符串列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有串的名单,这是最有可能的,但不能保证包含数字组成的列表,即

I have a list of string, which is most likely, but not guaranteed to contain a list of numerics, i.e.,

{"1", "6", "2", "21", "89"}

什么是排序的字符串列表,以便它总是会出现按升序排列的方式?

What is the way to sort the string list so that it will always appear in ascending order?

我无法解析字符串做简单排序前第一个数字因为字符串的可以包含非数字字符。我不想去通过列表并检查铸每个组件数字和进行排序。是否有已经存在在那里用于此目的的图书馆吗?

I can't parse the string to numeric first before doing the sorting simply because the string can contain non numeric characters. And I don't want to go through the list and check-cast each component to numerics and do the sorting. Is there already a library existing out there for this purpose?

在我们拥有混合数字和非数字的字符串项,数字串始终优先的情况下在非数字的。

推荐答案

这已经问略有不同,但相同的答案仍然适用,

This has been asked before slightly differently, but the same answer still applies, as they have a C# implementation on the same site.

SO问题一个字符串 - 即,可能-包含一个数字>排序上的绳子可能包含一些通过在

SO Question: Sort on a string that may contain a number

答= http://stackoverflow.com/users/1310/scarcher2\">ScArcher2 的Alphanum算法

Answer provided by ScArcher2: The Alphanum Algorithm

这篇关于带数值排序字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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