For a current programming project I am doing I need the ability to convert words containing non-ASCII umlauts like 'ä', 'ö' or 'ü' into words/Strings containing Unicode (\u00F6
).
To achieve this I wanted to try out the 'new' Java Streams. So far I was able to obtain all indices of characters that would not fit in the default ASCII charset and thus need to be replaced.
public static void replaceUmlauts() {
char[] chars = "persönlich".toCharArray();
int[] ind = IntStream.range(0, chars.length).filter(i -> chars[i] > 128).toArray();
}
Yet I do not really find a way to nicely replace the umlauts at the identified indices with their respective Unicode representations. To stay with one paradigm I would like to find a Stream solution, but I would also be open to other efficient solutions to solve the problem.
Also completely different - maybe even easier approaches - to the whole problems would be well appreciated.