C# ArrayList的排序
C#stringaaa="agbc5,dhk721,klkk32,duuoj01";//逗号前有数字ArrayListarrl=newArrayList();arrl.A...
C#
string aaa = "agbc5,dhk721,klkk32,duuoj01";//逗号前有数字
ArrayList arrl = new ArrayList();
arrl.AddRange(aaa.split(','); //根据 , 把aaa的值分别赋给arrl数组
怎么根据每行数组里的数字来排序arrl数组,从大往小
我用的是:vs2008, 2.0 Fremwork 展开
string aaa = "agbc5,dhk721,klkk32,duuoj01";//逗号前有数字
ArrayList arrl = new ArrayList();
arrl.AddRange(aaa.split(','); //根据 , 把aaa的值分别赋给arrl数组
怎么根据每行数组里的数字来排序arrl数组,从大往小
我用的是:vs2008, 2.0 Fremwork 展开
2个回答
展开全部
using System;
using System.Collections;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string aaa = "agbc5,dhk721,klkk32,duuoj01";
ArrayList arrl = new ArrayList();
arrl.AddRange(aaa.Split(','));
for (int i = 0; i < arrl.Count - 1; i++)
{
for (int j = i; j < arrl.Count; j++)
{
if (GetNumber(arrl[i].ToString()) < GetNumber(arrl[j].ToString()))
{
object temp = arrl[i];
arrl[i] = arrl[j];
arrl[j] = temp;
}
}
}
foreach (object item in arrl)
{
Console.WriteLine(item);
}
}
internal static int GetNumber(string str)
{
Regex regex = new Regex(@"\d+");
return int.Parse(regex.Match(str).Value);
}
}
}
using System.Collections;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string aaa = "agbc5,dhk721,klkk32,duuoj01";
ArrayList arrl = new ArrayList();
arrl.AddRange(aaa.Split(','));
for (int i = 0; i < arrl.Count - 1; i++)
{
for (int j = i; j < arrl.Count; j++)
{
if (GetNumber(arrl[i].ToString()) < GetNumber(arrl[j].ToString()))
{
object temp = arrl[i];
arrl[i] = arrl[j];
arrl[j] = temp;
}
}
}
foreach (object item in arrl)
{
Console.WriteLine(item);
}
}
internal static int GetNumber(string str)
{
Regex regex = new Regex(@"\d+");
return int.Parse(regex.Match(str).Value);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询