wszelki wypadek ktoś używa theese ręcznie robione funkcje:
public static String superscript(String str) {
str = str.replaceAll("0", "⁰");
str = str.replaceAll("1", "¹");
str = str.replaceAll("2", "²");
str = str.replaceAll("3", "³");
str = str.replaceAll("4", "⁴");
str = str.replaceAll("5", "⁵");
str = str.replaceAll("6", "⁶");
str = str.replaceAll("7", "⁷");
str = str.replaceAll("8", "⁸");
str = str.replaceAll("9", "⁹");
return str;
}
public static String subscript(String str) {
str = str.replaceAll("0", "₀");
str = str.replaceAll("1", "₁");
str = str.replaceAll("2", "₂");
str = str.replaceAll("3", "₃");
str = str.replaceAll("4", "₄");
str = str.replaceAll("5", "₅");
str = str.replaceAll("6", "₆");
str = str.replaceAll("7", "₇");
str = str.replaceAll("8", "₈");
str = str.replaceAll("9", "₉");
return str;
}
uwaga, że jest tam trochę niejednoznaczności o ¹²³, ponieważ są one ACII symobls 251, 253 i 252 i są one również UTF-symbole. Wolę używać acsii, ponieważ prawdopodobnie są one wspierane czcionką, ale tutaj powinieneś opisać to, czego chcesz używać.
Java String jest po prostu zbiorem znaków, czyli zwykłego tekstu .. –
... Cóż. Jeśli chcesz indeksów górnych w przeglądarce, będziesz musiał użyć CSS lub HTML. Ciąg jest po prostu ciągiem, nie ma żadnego wewnętrznego formatowania. –
Nie wiem, dlaczego wszyscy mówią o elementach graficznych i czcionkach. OP, proszę wyjaśnić swoje pytanie: gdzie i jak będzie wyświetlany ten ciąg? –