Android String to Int Convert getFirstInteger(String value)

Here you can find the source of getFirstInteger(String value)

Description

get First Integer

Declaration

public static int getFirstInteger(String value) 

Method Source Code

//package com.java2s;

public class Main {
    public static int getFirstInteger(String value) {
        StringBuilder sb = new StringBuilder();
        char[] charArray = value.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            if (charArray[i] >= '0' && charArray[i] <= '9') {
                sb.append(charArray[i]);
            } else {
                break;
            }/*from   w ww  .  ja  va 2s  .c  om*/
        }
        return (sb.length() == 0 ? 0 : Integer.parseInt(sb.toString()));
    }
}

Related

  1. string2Int(String str)
  2. isTextInteger(String texto)
  3. getInt(String str, int defaultValue)
  4. getIntFromStr(String str)
  5. getIntValue(String str)
  6. tryParse(String value, int defaultValue)
  7. tryParse(String value, String defaultValue)
  8. parseInt(String str)
  9. parseInt(String arg, int defaultValue)