Reputation: 1665
I am trying to compare two string
"Food & Beverages" == "Food & Beverages"
and result I am getting is false. This is because the ascii value of the character 7 is different in & ASCII Number: 38
& ASCII Number: 65286
One value is from database and other is from file. is there a way to compare these two string?
in powershell they are asking to normalise the string.
How to compare strings that have an ampersand in them in PowerShell
Is there similar thing available in flutter?
Upvotes: 2
Views: 556
Reputation: 2031
The easiest way is probably to remove these characters before you compare two string.
So something like:
String cleanString(String s) {
return s.replaceAll(RegExp('[^a-zA-Z0-9 ]*'), '');
}
bool compare(String s1, String s2) {
return cleanString(s1) == cleanString(s2);
}
Upvotes: 1
Reputation: 316
You should replace the characters before the comparison. I think this is the best way,
Upvotes: 1