I'm trying to print the first 30 characters of some UTF-8 strings, and notice that Java's String.substring() is returning some funky strings. I've boiled it down to:
I'm expecting "
I'm pretty sure (1 2) the UTF-8 encoding for
0xF0 0x9F 0xA4 0xA3 And so I expect this tiny program:
import java.nio.charset.StandardCharsets; public class Foo { public static void main(String[] args){ String str = "
true 1
true 2 ? Am I doing something wrong?
I've tried an custom java 11.0.20.1 build and these standard Ubuntu packages with the same results:
$ javac -version javac 19.0.2 $ java -version openjdk version "19.0.2" 2023-01-17 OpenJDK Runtime Environment (build 19.0.2+7-Ubuntu-0ubuntu322.04) OpenJDK 64-Bit Server VM (build 19.0.2+7-Ubuntu-0ubuntu322.04, mixed mode, sharing)
Источник: https://stackoverflow.com/questions/781 ... r-laughing
Мобильная версия