Recent

Author Topic: display unicode character in cmd apps  (Read 739 times)

kjteng

  • Sr. Member
  • ****
  • Posts: 259
display unicode character in cmd apps
« on: March 07, 2024, 09:30:25 am »
I need to display utf8 string in console (using write and writeln command). Initially everything was fine... until I added crt to the uses clause.
All the utf8 string now became '?'.  After searching the forum, I found 'unicodecrt' unit which is supposed to be unicode enabled (https://forum.lazarus.freepascal.org/index.php/topic,35037.msg302211.html#msg302211). With this unit, the writeln command is able to display utf8 string but some characters are missing (everty alternative character  is missing - see screen shot attached). However if I use WriteConsole API then all the whole string will be displayed. 
What can I do to make the writeln command work properly?
My code is as follows:
Code: Pascal  [Select][+][-]
  1.   s1 := '一一二二三四五六七八九十';
  2.   writeln(s1);
  3.   WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), @s1[1], Length(s1), nil, nil);
  4.   writeln;
  5.   writeln;
  6.  
  7.   s2 := 'あ'+'あ'+'が'+'が'+'あ'+'が'+ 'に'+ 'に';
  8.   writeln(s2);
  9.   WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), @s2[1], Length(s2), nil, nil);
  10.   readln;  
TQ

 

 

TinyPortal © 2005-2018