How to sort out numeric strings as numerics?

前端 未结 6 2010
面向向阳花
面向向阳花 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条回答
  •  Happy的楠姐
    2020-12-30 09:28

    Do I have to parse the string and convert it into a number for this?

    Essentially, yes; but LINQ may help:

    var sorted = arr.OrderBy(s => int.Parse(s.Substring(5)));
    foreach (string s in sorted) {
        Console.WriteLine(s);
    }
    

提交回复
热议问题