如何仅从颤振中的字符串中提取数字? [英] How to extract number only from string in flutter?

查看:67
本文介绍了如何仅从颤振中的字符串中提取数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个字符串:

Lets say that I have a string:

a="23questions";
b="2questions3";

现在我需要从两个字符串中解析23。如何从字符串值中提取该数字或任何数字?

Now I need to parse 23 from both string. How do I extract that number or any number from a string value?

推荐答案

以下代码可以提取该数字:

The following code can extract the number:

aStr = a.replaceAll(new RegExp(r'[^0-9]'),''); // '23'

您可以使用以下方法将其解析为整数:

You can parse it into integer using:

aInt = int.parse(aStr);

这篇关于如何仅从颤振中的字符串中提取数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆