class Strn_comparer : IComparer {
#region IComparer メンバ
public int Compare(string x, string y) {
int t = Norm(x).CompareTo(Norm(y));
if (t != 0) return t;
return x.CompareTo(y);
}
static string Norm(string x) {
return Regex.Replace(x, "\\d+", Pad);
}
static string Pad(Match M) {
return M.Value.PadLeft(19, '0');
}
#endregion
}
C-1 → C-0000000000000000001
C-11 → C-0000000000000000011
C-2 → C-0000000000000000002
これで単純な文字列比較ができるようになります。
しかし、文字列が長くなり、メモリも消費しまくりなきらいは有ります。
いかがなものでしょうか。
0 件のコメント:
コメントを投稿