list - Dart - 从列表中提取数字
问题描述
我有一个包含彩票号码 列表图像的列表
如何分隔数字和文本,然后在下面的列表中列出它们:例如:
List<String> n = ["ABC23", "21A23", "12A312","32141A"];
谢谢!
解决方案
您可以通过使用 forEach 来做到这一点,如下所示:
List<String> n = ["23", "2123", "12312","32141"];
n.forEach((element) =>
print(element)
);
要分隔数字和文本,您可以使用以下代码:
const text = '''
Lorem Ipsum is simply dummy text of the 123.456 printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an 12:30 unknown printer took a galley of type and scrambled it to make a
23.4567
type specimen book. It has 445566 survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
''';
final intRegex = RegExp(r'\s+(\d+)\s+', multiLine: true);
final doubleRegex = RegExp(r'\s+(\d+\.\d+)\s+', multiLine: true);
final timeRegex = RegExp(r'\s+(\d{1,2}:\d{2})\s+', multiLine: true);
void main() {
print(intRegex.allMatches(text).map((m) => m.group(0)));
print(doubleRegex.allMatches(text).map((m) => m.group(0)));
print(timeRegex.allMatches(text).map((m) => m.group(0)));
}
请参阅此链接了解更多信息。
推荐阅读
- c++ - 无法将带有秒数的字符串从纪元转换为 date_time
- ios - 如何保存 pushNotification 附带的两个项目
- css - 如何为特定的缩放级别调整 CSS?
- android - 我想更改 RecyclerView 中的 Button TextColor
- angular - ng build --prod 非导出函数
- python - 如何在pycharm中安装spacy?
- xamarin - 如何在 Xamarin.Forms 的工具栏项上方设置徽章计数器?
- ios - 从 iPhone gmail 应用打开所有链接会打开我的应用
- javascript - 使用异步属性时 Javascript 不起作用:Highcharts
- variables - 在 Dart 中直接将实例属性打印到控制台的正确语法(不仅仅是打印范围内的变量)