I have a list of strings and one if it's items looks like this '19-06-2022 12:37' ..
How can i remove any pattern like this if it exist in the list using Dart language ?
You can remove any pattern from string by using String class method replaceAll
. If you want to remove any pattern then you need to use RegExp like below example.
There are also other method like replaceFirst
, replaceRange
for more details Read Here
String testSt = "12-02-2022 16:23";
String myPattern = "^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2}) [012]{0,1}[0-9]:[0-6][0-9]";
testSt.replaceAll(new RegExp(myPattern),"");
You can try like this:
List<String> stringList = ["20-11-2022 12:37", "19-06-2022 12:37", "19-03-2022 12:37", "09-06-2022 12:37", "x", "y", "z","w"];
stringList = stringList.where((element) => !element.contains("-")).toList();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.