Java Char Array to Int charArrayToInt(char[] data, int start, int length, int[] end)

Here you can find the source of charArrayToInt(char[] data, int start, int length, int[] end)

Description

char Array To Int

License

Open Source License

Declaration

public static int charArrayToInt(char[] data, int start, int length, int[] end) throws NumberFormatException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int charArrayToInt(char[] data, int start, int length, int[] end) throws NumberFormatException {
        boolean neg = false;
        if (data[start] == '-') {
            neg = true;// w w w .ja v  a2 s  . co  m
            start++;
        } else if (data[start] == '+') {
            start++;
        }
        int result = 0;
        int i;
        for (i = start; i < length; i++) {
            int digit = data[i] - '0';
            if (digit < 0 || digit > 9) {
                return result;
            }
            result = result * 10 + digit;
        }
        end[0] = i;
        return neg ? -result : result;
    }
}

Related

  1. charArrayDecimalToInt(char[] str, int start, int len, int mul)
  2. charArrayDigitToInt(char[] str, int start, int len)
  3. charArrayHexToInt(char[] str, int start, int len)
  4. charsToInt(char[] chars, int offset)