How to sort out numeric strings as numerics?

前端 未结 6 2027
面向向阳花
面向向阳花 2020-12-30 09:04

If you have strings like:

\"file_0\"
\"file_1\"
\"file_2\"
\"file_3\"
\"file_4\"
\"file_5\"
\"file_6\"
\"file_11\"

how can you sort them so

6条回答
  •  醉酒成梦
    2020-12-30 09:19

    The following code based on Joey's suggestion works for me (extension method to string[]):

    public static void SortLogical(this string[] files)
    {
        Array.Sort(files, new Comparison(StrCmpLogicalW));
    }
    
    [DllImport("shlwapi.dll", CharSet=CharSet.Unicode, ExactSpelling=true)]
    private static extern int StrCmpLogicalW(String x, String y);
    

提交回复
热议问题