Compartilhar via


Integer.ParseInt Method

Definition

Overloads

ParseInt(String)

Parses the string argument as a signed decimal integer.

ParseInt(String, Int32)

Parses the string argument as a signed integer in the radix specified by the second argument.

ParseInt(ICharSequence, Int32, Int32, Int32)

Parses the CharSequence argument as a signed int in the specified radix, beginning at the specified beginIndex and extending to endIndex - 1.

ParseInt(String, Int32, Int32, Int32)

Parses the CharSequence argument as a signed int in the specified radix, beginning at the specified beginIndex and extending to endIndex - 1.

ParseInt(String)

Parses the string argument as a signed decimal integer.

[Android.Runtime.Register("parseInt", "(Ljava/lang/String;)I", "")]
public static int ParseInt (string s);
[<Android.Runtime.Register("parseInt", "(Ljava/lang/String;)I", "")>]
static member ParseInt : string -> int

Parameters

s
String

a String containing the int representation to be parsed

Returns

the integer value represented by the argument in decimal.

Attributes

Exceptions

if string cannot be parsed as an integer value.

Remarks

Parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u005Cu002D') to indicate a negative value or an ASCII plus sign '+' ('\u005Cu002B') to indicate a positive value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the #parseInt(java.lang.String, int) method.

Java documentation for java.lang.Integer.parseInt(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

ParseInt(String, Int32)

Parses the string argument as a signed integer in the radix specified by the second argument.

[Android.Runtime.Register("parseInt", "(Ljava/lang/String;I)I", "")]
public static int ParseInt (string s, int radix);
[<Android.Runtime.Register("parseInt", "(Ljava/lang/String;I)I", "")>]
static member ParseInt : string * int -> int

Parameters

s
String

the String containing the integer representation to be parsed

radix
Int32

the radix to be used while parsing s.

Returns

the integer represented by the string argument in the specified radix.

Attributes

Exceptions

if string cannot be parsed as an integer value, or radix Character.MAX_RADIX.

Remarks

Parses the string argument as a signed integer in the radix specified by the second argument. The characters in the string must all be digits of the specified radix (as determined by whether java.lang.Character#digit(char, int) returns a nonnegative value), except that the first character may be an ASCII minus sign '-' ('\u005Cu002D') to indicate a negative value or an ASCII plus sign '+' ('\u005Cu002B') to indicate a positive value. The resulting integer value is returned.

An exception of type NumberFormatException is thrown if any of the following situations occurs: <ul> <li>The first argument is null or is a string of length zero.

<li>The radix is either smaller than java.lang.Character#MIN_RADIX or larger than java.lang.Character#MAX_RADIX.

<li>Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign '-' ('\u005Cu002D') or plus sign '+' ('\u005Cu002B') provided that the string is longer than length 1.

<li>The value represented by the string is not a value of type int. </ul>

Examples: <blockquote>

parseInt("0", 10) returns 0
            parseInt("473", 10) returns 473
            parseInt("+42", 10) returns 42
            parseInt("-0", 10) returns 0
            parseInt("-FF", 16) returns -255
            parseInt("1100110", 2) returns 102
            parseInt("2147483647", 10) returns 2147483647
            parseInt("-2147483648", 10) returns -2147483648
            parseInt("2147483648", 10) throws a NumberFormatException
            parseInt("99", 8) throws a NumberFormatException
            parseInt("Kona", 10) throws a NumberFormatException
            parseInt("Kona", 27) returns 411787

</blockquote>

Java documentation for java.lang.Integer.parseInt(java.lang.String, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

ParseInt(ICharSequence, Int32, Int32, Int32)

Parses the CharSequence argument as a signed int in the specified radix, beginning at the specified beginIndex and extending to endIndex - 1.

[Android.Runtime.Register("parseInt", "(Ljava/lang/CharSequence;III)I", "", ApiSince=33)]
public static int ParseInt (Java.Lang.ICharSequence s, int beginIndex, int endIndex, int radix);
[<Android.Runtime.Register("parseInt", "(Ljava/lang/CharSequence;III)I", "", ApiSince=33)>]
static member ParseInt : Java.Lang.ICharSequence * int * int * int -> int

Parameters

s
ICharSequence

the CharSequence containing the int representation to be parsed

beginIndex
Int32

the beginning index, inclusive.

endIndex
Int32

the ending index, exclusive.

radix
Int32

the radix to be used while parsing s.

Returns

the signed int represented by the subsequence in the specified radix.

Attributes

Remarks

Parses the CharSequence argument as a signed int in the specified radix, beginning at the specified beginIndex and extending to endIndex - 1.

The method does not take steps to guard against the CharSequence being mutated while parsing.

Added in 9.

Java documentation for java.lang.Integer.parseInt(java.lang.CharSequence, int, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

ParseInt(String, Int32, Int32, Int32)

Parses the CharSequence argument as a signed int in the specified radix, beginning at the specified beginIndex and extending to endIndex - 1.

public static int ParseInt (string s, int beginIndex, int endIndex, int radix);
static member ParseInt : string * int * int * int -> int

Parameters

s
String

the CharSequence containing the int representation to be parsed

beginIndex
Int32

the beginning index, inclusive.

endIndex
Int32

the ending index, exclusive.

radix
Int32

the radix to be used while parsing s.

Returns

the signed int represented by the subsequence in the specified radix.

Remarks

Parses the CharSequence argument as a signed int in the specified radix, beginning at the specified beginIndex and extending to endIndex - 1.

The method does not take steps to guard against the CharSequence being mutated while parsing.

Added in 9.

Java documentation for java.lang.Integer.parseInt(java.lang.CharSequence, int, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to