dart:core
庫中num.tryParse
方法的用法介紹如下。
用法:
num? tryParse(
String input
)
將包含數字文字的字符串解析為數字。
與 parse 類似,隻是此函數針對無效輸入返回 null
而不是拋出異常。
例子:
var value = num.tryParse('2021'); // 2021
value = num.tryParse('3.14'); // 3.14
value = num.tryParse(' 3.14 \xA0'); // 3.14
value = num.tryParse('0.'); // 0.0
value = num.tryParse('.0'); // 0.0
value = num.tryParse('-1.e3'); // -1000.0
value = num.tryParse('1234E+7'); // 12340000000.0
value = num.tryParse('+.12e-9'); // 1.2e-10
value = num.tryParse('-NaN'); // NaN
value = num.tryParse('0xFF'); // 255
value = num.tryParse(double.infinity.toString()); // Infinity
value = num.tryParse('1f'); // null
相關用法
- Dart num.toStringAsExponential用法及代碼示例
- Dart num.toStringAsPrecision用法及代碼示例
- Dart num.toStringAsFixed用法及代碼示例
- Dart num.toString用法及代碼示例
- Dart num.sign用法及代碼示例
- Dart num.abs用法及代碼示例
- Dart num.remainder用法及代碼示例
- Dart num.compareTo用法及代碼示例
- Dart num.operator_modulo用法及代碼示例
- Dart num.parse用法及代碼示例
- Dart num.clamp用法及代碼示例
- Dart MapMixin.containsKey用法及代碼示例
- Dart Iterator用法及代碼示例
- Dart AttributeClassSet.intersection用法及代碼示例
- Dart TransformList.last用法及代碼示例
- Dart FileList.first用法及代碼示例
- Dart CanvasRenderingContext2D.drawImageScaledFromSource用法及代碼示例
- Dart FileList.length用法及代碼示例
- Dart Iterable.takeWhile用法及代碼示例
- Dart LinkedHashMap用法及代碼示例
- Dart RegExp.pattern用法及代碼示例
- Dart StreamTransformer構造函數用法及代碼示例
- Dart JsArray.removeAt用法及代碼示例
- Dart ListMixin.expand用法及代碼示例
- Dart UriData.parse用法及代碼示例
注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 tryParse method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。