1

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 1

1

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Nice! Thanks for a fast answer! I just tested and your code works exactly as I wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.