Java tutorial
//package com.java2s; public class Main { public static int stringCompareHonoringUnsigned(String inA, String inB) { int i, n, an, bn; int ai = 0, bi = 0; char al, bl; an = inA.length(); bn = inB.length(); n = (an < bn) ? an : bn; for (i = 0; i < n; ++i) { al = inA.charAt(i); bl = inB.charAt(i); if (al >= '0' && al <= '9' && bl >= '0' && bl <= '9') { ai = stringToUnsigned(inA, i); bi = stringToUnsigned(inB, i); break; } else if (al != bl) { break; } } return (ai > bi) ? 1 : (ai < bi) ? -1 : (i < n) ? inA.compareTo(inB) : (an > bn) ? 1 : (an < bn) ? -1 : 0; } public static int stringToUnsigned(String inString, int inStart) { int result = 0; int index, count = inString.length(); // does not account for integer overflow, sign, decimal, or other bases for (index = inStart; index < count; ++index) { char letter = inString.charAt(index); if (letter >= '0' && letter <= '9') { result = (result * 10) + (letter - '0'); } else break; } return result; } }