Reputation: 11
I intend to replace strings with normal strings into split strings, but there is a difference in length between the normal strings which amounts to 62 and the split length turns out to be 117, so when we write the 'a' button it doesn't change to 'π' is there another way of writing replace string easier?
public static String doublestruck(String input){
String normal = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
String split = "πππππππππ π‘ππππππππππππ π‘π’π£π€π₯π¦π§π¨π©πͺπ«πΈπΉβπ»πΌπ½πΎβπππππβπβββπππππππβ€";
String output = "";
char letter;
for(int i = 0; i < input.length(); i++){
letter = input.charAt(i);
int a = normal.indexOf(letter);
output += (a != -1) ? split.charAt(a):letter;
}
return new StringBuilder(output).toString();
}
Upvotes: 0
Views: 75
Reputation: 308031
The letters like π (U+1D7DC) are not in the Basic Multilingual Pane and thus take up two char
values in Java.
Instead of charAt
you need to use codePointAt
and to find the correct offset you need to use offsetByCodePoint
instead of directly using the same index. So split.charAt(a)
needs to be replaced by split.codePointAt(spli.offsetByCodePoint(0, a))
.
Upvotes: 1