Android String to Int Convert parseInt(String str)

Here you can find the source of parseInt(String str)

Description

Parses an string to integer by removing any non-integer character

Parameter

Parameter Description
str The input integer value as a string

Return

The converted integer value (I.E. 1,000 becomes 1000) returns 0 if fails

Declaration

public static int parseInt(String str) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w ww  .j  av  a 2s .  com*/
     * Parses an string to integer by removing any non-integer character
     * @param str The input integer value as a string
     * @return The converted integer value (I.E. 1,000 becomes 1000) returns 0 if fails
     */
    public static int parseInt(String str) {
        str = str.replaceAll("[^0-9]+", "");

        try {
            return Integer.parseInt(str);
        } catch (Exception e) {
            return 0;
        }
    }
}

Related

  1. getIntFromStr(String str)
  2. getIntValue(String str)
  3. getFirstInteger(String value)
  4. tryParse(String value, int defaultValue)
  5. tryParse(String value, String defaultValue)
  6. parseInt(String arg, int defaultValue)
  7. stringToIntArray(String arrString, String separator)
  8. getIntegerArrayList(String strInput)
  9. validInt(CharSequence integer)