I need to convert String
s that consists of some letters specific to certain languages (like HÄSTDJUR - note Ä) to a String
without those special le
I think your question is the same as this one:
Java - getting rid of accents and converting them to regular letters
and hence the answer is also the same:
String convertedString =
Normalizer
.normalize(input, Normalizer.Form.NFD)
.replaceAll("[^\\p{ASCII}]", "");
See
final String input = "Tĥïŝ ĩš â fůňķŷ Šťŕĭńġ";
System.out.println(
Normalizer
.normalize(input, Normalizer.Form.NFD)
.replaceAll("[^\\p{ASCII}]", "")
);
Output:
This is a funky String
I'd suggest a mapping, of special characters, to the ones you want.
Ä --> A
é --> e
A --> A (exactly the same)
etc...
And then you can just call your mapping over your text (in pseudocode):
for letter in string:
newString += map(letter)
Effectively, you need to create a set of rules for what character maps to the ASCII equivalent.