Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace similar cyrillic and english characters

Tags:

java

string

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?

like image 372
olgacosta Avatar asked Jan 12 '15 12:01

olgacosta


1 Answers

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.

like image 173
Bohemian Avatar answered Nov 15 '22 03:11

Bohemian