Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:core
  3. int
  4. parse static method
parse
description

parse static method

intparse(
  1. Stringsource, {
  2. int?radix,
})
override

Parsesource as a, possibly signed, integer literal and return its value.

Thesource must be a non-empty sequence of base-radix digits,optionally prefixed with a minus or plus sign ('-' or '+').

Theradix must be in the range 2..36. The digits used arefirst the decimal digits 0..9, and then the letters 'a'..'z' withvalues 10 through 35. Also accepts upper-case letters with the samevalues as the lower-case ones.

If noradix is given then it defaults to 10. In this case, thesourcedigits may also start with0x, in which case the number is interpretedas a hexadecimal integer literal,Whenint is implemented by 64-bit signed integers,hexadecimal integer literals may represent values larger than263, in which case the value is parsed as if it is anunsigned number, and the resulting value is the correspondingsigned integer value.

For any intn and valid radixr, it is guaranteed thatn == int.parse(n.toRadixString(r), radix: r).

If thesource string does not contain a valid integer literal,optionally prefixed by a sign, aFormatException is thrown.

Rather than throwing and immediately catching theFormatException,instead usetryParse to handle a potential parsing error.

Example:

var value = int.tryParse(text);if (value == null) {  // handle the problem  // ...}

Implementation

external static int parse(String source, {int? radix});
  1. Dart
  2. dart:core
  3. int
  4. parse static method
int class

[8]ページ先頭

©2009-2025 Movatter.jp