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".
1 Answer
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;
}
1 Comment
Arvis Iljins
Nice! Thanks for a fast answer! I just tested and your code works exactly as I wanted.