Search code examples
androidxiaomi

String replace isn't working for some cyrillic characters


For some reason I need to replace cyrillic letter "Ё" with "Е". So I wrote this simple code

someString = someString.toLowerCase().replace("ё", "е");

It's working perfectly fine on emulators and most of my devices, except Xiaomi Redmi 9a. The app doesn't replace "ё" on Xiaomi at all.

What can be wrong?


Solution

  • Xiaomi Redmi 9a doesn't use cyrillic letter "Ё", it uses "Ë"! :) It's latin letter "E" with diaeresis. I don't know is it because of keyboard or something else.

    So we need to change code to this

    // The first character of pattern is cyrillic Ё, the second is latin E with diaeresis. 
    // Some Xiaomi devices use the second variant instead of cyrillic letter
    someString = someString.toLowerCase().replaceAll("[ёë]", "е");
    

    or this

    someString = someString.toLowerCase().replace("ё", "е").replace("ë", "е");