0
我試着循環遍歷字符串中的字符並打印出來。除了Deseret Long I()以外,他們都打印得很好。我不知道是否有其他方法可以做到這一點,以便正確打印。這裏是我的代碼:Java:如何遍歷字符串中具有代理對的字符並將其打印出來?
package javaapplication13;
public class JavaApplication13 {
public static void main(String[] args) {
String s = "hy\u0500";
System.out.println(s);
final int length = s.length();
for (int offset = 0; offset < length;) {
final int codepoint = s.codePointAt(offset);
System.out.println((char) (codepoint));
offset += Character.charCount(codepoint);
}
}
}
輸出看起來像這樣(Netbeans的):
run:
hyԀ
h
䍡
y
Ѐ
Ԁ
BUILD SUCCESSFUL (total time: 0 seconds)
'System.out.println(Character.toChars(codepoint));'工作!謝謝! –