有哪些方法可以避免 String.substring 返回带有无效 unicode 字符的子字符串? char obsoleteCode point
最近,只有我注意到,有可能返回带有无效unicode字符的字符串。substring
例如
public class Main {
public static void main(String[] args) {
String text = "
最近,只有我注意到,有可能返回带有无效unicode字符的字符串。substring
例如
public class Main {
public static void main(String[] args) {
String text = "
char
obsoleteThe char
type has been legacy since Java 2, essentially broken. As a 16-bit value, char
is physically incapable of representing most characters.
Your discovery suggests that the String#substring
command is char
based. Hence the problem shown in your code.
Instead, use code point integer numbers when working with individual characters.
int[] codePoints = "