我想拆分一些字符串并将每一行包含在数组中的单独元素中。我使用此代码来实现我的目标:
List _masForUsing;
_masForUsing = new List(numberOfLines);
void gpsHelper(String text, int count){
for(int i =0; i<count;i++){
_masForUsing[i] = text.split("\\r?\\n");
}
print(_masForUsing[2]);
}
Run Code Online (Sandbox Code Playgroud)
但是当我想唤起数组的第三个元素时,它只显示完整的字符串。请帮我 :)
这是字符串的示例:
Run Code Online (Sandbox Code Playgroud)real time: 23-09-2019, 23:08:55, Mon system time: 5362 gps coordinates: 55.376538; 037.431973; gps satellites: 3; gps time: 20:09:02; gps date: 23.09.19; temperature: 19 *C humidity: 35 % dust: 1 zivert: 21
使用 Dart 内置的LineSplitter,它是独立于系统的。
void gpsHelper(String text) {
LineSplitter ls = new LineSplitter();
List<String> _masForUsing = ls.convert(text);
//print(_masForUsing[2]); // gps coordinates: 55.376538; 037.431973;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
200 次 |
| 最近记录: |