countExactMatchesAndAppend method
Takes a String list, list
, and counts the exact matches to this
.
Then, it appends the number of occurence found inside the list to this
.
Ex: list: test, test1, test (1), test (2) this: test Output: test (3)
Implementation
String countExactMatchesAndAppend(List<String> list) {
int count = 0;
for (String item in list) {
RegExp regex = RegExp("(\\b$this\\b\\s[()][0-9][()])");
if (regex.hasMatch(item) || item == this) count++;
}
return count > 0 ? "$this ($count)" : this;
}