The version looks like the easiest way, however, if you need unlimited "decimal places", try below
private int multiDecCompare(string str1, string str2) { try { string[] split1 = str1.Split('.'); string[] split2 = str2.Split('.'); if (split1.Length != split2.Length) return -99; for (int i = 0; i < split1.Length; i++) { if (Int32.Parse(split1[i]) > Int32.Parse(split2[i])) return 1; if (Int32.Parse(split1[i]) < Int32.Parse(split2[i])) return -1; } return 0; } catch { return -99; } }
Returns 1 if the first line goes more from left to right, -1 if the line is 2, 0 if it is equal, and -99 for an error.
So, return 1 for
string str1 = "11.30.42.29.66"; string str2 = "11.30.30.10.88";
source share