I have a text box where the user can input the string with letters and numbers in Java, i.e.
String inputString="Аs87df56VСХ6ВР";
And also the user can forget to switch the language and input this string using cyrillic alphabet, because there are similar characters in cyrillic and english alphabets: ABCEHKMOPTX
My question is: how to find and replace cyrillic letters in the input string?
Use the replaceChars()
utility method from the StringUtils
class of the Apache common-lang library.
str = StringUtils.replaceChars(str, "АВЕЅZІКМНОРСТХШѴУ", "ABESZIKMHOPCTXWVY");
I used actual Cyrillic chars in this code (so you can copy-paste it) and added a couple of moderately similar letters too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With