简体   繁体   English

在 dart-flutter 中将字符串拆分为列列表

[英]split a String into colums list in dart-flutter

How to split this "example#example" To show like this如何拆分这个“example#example”来显示这样

like columns 1.example 2.example像列 1.example 2.example

final String list = data!.list!.split('#').first;

result >>>> example结果>>>>例子

How to show如何展示

example
example 

from example#example来自example#example

You can change list type to var and get rid of first您可以将列表类型更改为 var 并first摆脱

String data = "example#example";
var list = data.split('#');
print(list);

data.split('#') will provide a list. data.split('#')将提供一个列表。 You can loop though item.您可以循环遍历项目。

  final data = "example#example";
  final list = data.split('#');
  for (final item in list) { // will print one by one.
    print(item);
  }
  final outPut = list.join(" "); //You can join the list. 
  print(outPut); //example example

If you mean to widget not printing, here's a solution.如果你的意思是小部件不打印,这里有一个解决方案。

const String data = "example#example";
final List<String> list = data.split('#');
return Column(
  children: <Widget>[
    ...list.map((String e) => Text(e)),
  ],
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM