Reputation: 189
Hi i want to search whole word contain in a string for example i want to search bro it should only return true if separate word bro found like "Arjun bro" and returns false for "brodband" im using contains method but that is not giving desired output
Upvotes: 1
Views: 7065
Reputation: 27157
You can use Regular Expression To do so.
Following code help you more.
String search = 'Bro';
String str = 'Breo Brother abcBro';
@override
void initState() {
super.initState();
caseSensitive: false,
caseSensitive: false,
RegExp exp = new RegExp( "\\b" + search + "\\b", caseSensitive: false, );
bool containe = exp.hasMatch(str);
print(containe);
}
Output:
false
Note: correct first Bro in string then it will print true. It is case insensitive, so to make sensitive again remove caseSensitive: false.
Upvotes: 5