How could I replace the letters in a String such as "Hello", with the letters here?
String bubbled = "ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ";
I was initially just doing a replaceAll ("a","ⓐ"), but I feel like there has to be a more efficient way of doing this.
You could use the characters a
and ⓐ
to determine the offset values for the alphabet. In combination with a StringBuilder
it should be rather efficient. Of course you would likely have to be very strict about the input string being only alphabet characters.
This is the code for what I described above:
public class Bubbled {
public static void main(String[] args) {
char bubbledA = 'ⓐ';
int lowerCaseOffset = bubbledA - 'a';
int upperCaseOffset = bubbledA - 'A';
String input = "Hello";
StringBuilder bubbledOutput = new StringBuilder();
for (Character c : input.toCharArray()) {
if (Character.isUpperCase(c)) {
bubbledOutput.append((char)(c + upperCaseOffset));
} else {
bubbledOutput.append((char)(c + lowerCaseOffset));
}
}
System.out.println(bubbledOutput.toString());
}
}
Output
ⓗⓔⓛⓛⓞ
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments