110,533
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
string[] str = { "a1a.jpg", "a11a.jpg", "a12a.jpg", "a12b.jpg", "a7a.jpg" };
Array.Sort(str, delegate (string a, string b)
{
while (a != b)
{
string ta = Regex.Match(a, @"^[^\d]*").Value;
string tb = Regex.Match(b, @"^[^\d]*").Value;
if (ta != tb) return string.Compare(ta, tb);
a = Regex.Replace(a, @"^[^\d]*", "");
b = Regex.Replace(b, @"^[^\d]*", "");
ta = Regex.Match(a, @"^\d*").Value;
tb = Regex.Match(b, @"^\d*").Value;
double fa;
double fb;
double.TryParse(ta, out fa);
double.TryParse(tb, out fb);
if (fa != fb)
return Comparer<double>.Default.Compare(fa, fb);
a = Regex.Replace(a, @"^\d*", "");
b = Regex.Replace(b, @"^\d*", "");
}
return 0;
}
);
foreach (string s in str)
Console.WriteLine(s);
}