Reputation: 405
Maybe someone can help with advice. I need to change the string ''šķļī" to "skli" in flutter for search. For example, if the string contains "ŠODIEN" I need to fix it to "SODIEN" or "ŠOKOLĀDE" to "SOKOLADE".
Upvotes: 1
Views: 241
Reputation: 1865
if you want to translate one language to another then you can use translate package.
But if you want to convert it manually, then you can use this. Just make sure you added all the special characters in the switch case you want to convert.
void main() {
print(getNewString("šķļī"));
print(getNewString("ŠOKOLĀDE"));
}
String getNewString(String s){
String newString = "";
s.split('').forEach((a){
switch(a){
case "Š":
newString += "S";
break;
case "Ā":
newString += "A";
break;
case "š":
newString += "s";
break;
case "ķ":
newString += "k";
break;
case "ļ":
newString += "l";
break;
case "ī":
newString += "i";
break;
default:
newString += a;
break;
}
});
return newString;
}
Upvotes: 1