toInt method

int toInt()

将字符串转换为int

返回结果: 若字符串可正确转换为整数,则返回对应整数值;否则返回0。

示例:

print('123'.toInt()); // 123
print('abc'.toInt()); // 0

Implementation

int toInt() {
  return int.tryParse(this) ?? 0;
}