Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- class Program
- {
- static void Main()
- {
- string[] str = { "1_djjf", "12_shdfkj", "2_sdfsdf", "1112_sdfd", "10_blablabla" };
- str = str.OrderBy(x => x, new NaturalSort()).ToArray();
- foreach (var line in str)
- Console.WriteLine(line);
- }
- }
- public class NaturalSort : IComparer<string>
- {
- [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
- public static extern int StrCmpLogicalW(string x, string y);
- public int Compare(string x, string y)
- {
- return StrCmpLogicalW(x, y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment