I have a large string below the example of large string 👇
2023/03/11 11:14:30 N:21.234985 E:72.858528 4 km/h 275.15 -0.50Â 9 x:+0.000 y:+0.000 z:+0.000 2023/03/11 11:14:30 N:21.234987 E:72.858437 4 km/h 275.15 -8.90Â 9 x:+0.000 y:+0.000 z:+0.000 2023/03/11 11:14:32 N:21.234989 E:72.858452 0 km/h 270.92 -6.90Â 9 x:+0.000 y:+0.000 z:+0.000 2023/03/11 11:14:33 N:21.234995 E:72.858482 0 km/h 269.48 -3.60Â 9 x:+0.000 y:+0.000 z:+0.000 2023/03/11 11:14:34 N:21.234997 E:72.858505 0 km/h 275.53 -1.20Â 9 x:+0.000 y:+0.000 z:+0.000 2023/03/11 11:14:35 N:21.234999 E:72.858521 0 km/h 276.25 0.50Â 9 x:+0.000 y:+0.000 z:+0.000
I need to extract N and E from every line and i have two list like nList and eList and Every N element add into nList and every E element add into eList.
It’s possible in Flutter or Dart?
Thank you in advance for any help :}
Can you have any idea about it?
Here the attachment of .txt file for reference…
String File
>Solution :
You can iterate the list and retrieve values using a regular expression:
void main() {
String input =
"2023/03/11 11:14:30 N:21.234985 E:72.858528 4 km/h 275.15 -0.50 9 x:+0.000 y:+0.000 z:+0.000 2023/03/11 11:14:30 N:21.234987 E:72.858437 4 km/h 275.15 -8.90 9 x:+0.000 y:+0.000 z:+0.000 2023/03/11 11:14:32 N:21.234989 E:72.858452 0 km/h 270.92 -6.90 9 x:+0.000 y:+0.000 z:+0.000 2023/03/11 11:14:33 N:21.234995 E:72.858482 0 km/h 269.48 -3.60 9 x:+0.000 y:+0.000 z:+0.000 2023/03/11 11:14:34 N:21.234997 E:72.858505 0 km/h 275.53 -1.20 9 x:+0.000 y:+0.000 z:+0.000 2023/03/11 11:14:35 N:21.234999 E:72.858521 0 km/h 276.25 0.50 9 x:+0.000 y:+0.000 z:+0.000";
List<String> lines = input.split("\n"); // split input string into individual lines
List<String> nList = [];
List<String> eList = [];
for (final String line in lines) {
RegExp nRegExp = RegExp(r'N:(\d+\.\d+)');
RegExpMatch? nMatch = nRegExp.firstMatch(line);
if (nMatch != null && nMatch.group(1) != null) {
nList.add(nMatch.group(1)!);
}
RegExp eRegExp = RegExp(r'E:(\d+\.\d+)');
RegExpMatch? eMatch = eRegExp.firstMatch(line);
if (eMatch != null && eMatch.group(1) != null) {
eList.add(eMatch.group(1)!);
}
}
print(nList); // [21.234985]
print(eList); // [72.858528]
}