The following java code does exactly what is expected:
1 String s = "♪♬♪♪♬♪♪♬♪♪♬♪♪♬♪♪♬♪"; 2 for(int i=0; i < s.length(); i++) 3 { 4 System.out.print(s.substring(i,i+1)); 5 //System.out.print("\r"); 6 Thread.currentThread().sleep(500); 7 }
But when I try to add a carriage return by commenting out line 5, it prints. Why is this and how can I fix it?
(I also tried using "\ u240d" to return a carriage - the same thing).
EDIT: The output goes to bash on Mac OS X.
Java does not know what your source file is UTF-8.
If you compile
javac -encoding utf8 MyClass.java
and run
java -Dfile.encoding=utf8 MyClass
he will work.
(Does anyone know why UTF-8 is not the default?)
, s.length(), , 18. java - utf-16, String.substring char. 0x1d000 - char. / somthing like icu project - UCharacterIterator
ps: ,
, , .
, . , Java char 16 , char Unicode , String.substring .
char
String.substring
, , Java , . , . , , , .
, println("\r"), , . , , . 0x26, 0x6C, , 0x26, 0x10, 0x6C, 0x10, .
println("\r")
Source: https://habr.com/ru/post/1723441/More articles:Endless while loop in java - javaGet an array of 2 lines from HTML ... using regex? - arraysThe Importance of PHP in Web Oriented Platforms - phpWhich is preferable and cheaper: comparing classes with an exception? - javaA screensaver that not only disappears, but disappears to / from - user-interfacePublished TFS Manual Mstest Results? - command-lineКросс-платформенная обработка маршрута Unicode - c++Order from IF EXISTS - sqlWhy is a form class in a Windows Form application declared partial? - c #Странный контур при нажатии contentEditable div - javascriptAll Articles