Java tutorial
//package com.java2s; public class Main { public static int stringToInteger(String inString, int inStart) { int result = 0; char letter = inString.charAt(inStart); boolean negate = false; if (letter == '-') { inStart += 1; negate = true; } else if (letter == '+') { inStart += 1; } result = stringToUnsigned(inString, inStart); return negate ? -result : result; } 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; } }