i found here many question about How to remove Letters AFTER specific Letters but did not find AFTER-BEFORE specific Letters
i don't know if it possible in dart ..
sample
String test = 'HelloAflutterBHello'
so how to outputs the following result
print(test) => 'flutter'
that's mean i want to delete everything before ('A') and everything after ('B')
i tried this
print(test.substring(0, test.indexOf('B')));
but this will delete only anything after ('B') but couldn't find a way to delete the Letters before ('A') too ..
i hope any good answer . thanks
CodePudding user response:
You can use regular expressions to do the job. This way you can check for more than one character. Consider this code:
void main() {
String test = 'HelloABCflutterDEFHello';
//regex match all characters between two (or more) specified characters
RegExp exp = RegExp(r"(?<=ABC).*(?=DEF)");
//store all results from searching within a string.
Iterable<RegExpMatch> matches = exp.allMatches(test);
// access the captured value
print(matches.first.group(0));
}