How to translate strings using Java?
I want a translation routine that allows me to effectively translate any character into any other character or character set The obvious method seems to be to use the character value in the input string as the index of the 256 item conversion array
Given an initial array in which each entry is set to its value, for example, hex'37 'will appear in the 56th entry (00 is allowed to be the first), and then the user can replace any character required in the translation string
For example, I want to use the alphabetic character "a" for letters, the numeric character "n", the space character "B", and anything else "X" Therefore, "SL5 3qw" becomes "aanbnaa"
e. G.2. I want to translate some characters, such as“ œ” (x'9d ') to "OE" (x'6f65'), "ß" to "SS", "å" to "a", etc
How do I get a numeric value from a character in an input string to use as an index to a translate array?
Using the function code in excel is very simple, which is very simple in IBM assembler, but I can't track the method in Java
Solution
This is a bit off topic, but if you want to do a comprehensive character translation, you can't simply use string charAt(int). Unicode code points greater than 65535 are represented as two consecutive char values in Java strings
The clean way to handle this is to use string Codepointat (int) to extract each code point and use string Offsetbycodepoints (int, int) to execute the code point position step by step