Forum > General
concatenate two ansistring in console application
tetrastes:
--- Quote from: wp on March 03, 2024, 10:24:39 pm ---
--- Quote from: tetrastes on March 03, 2024, 10:01:24 pm ---Try this [...] with different CPs in SetConsoleOutputCP, and with and without LazUTF8.
--- End quote ---
A very non-Pascal-ish way to use WriteLn...
--- End quote ---
You mean using pchar(s)? But thus we can output utf8 without forcing users to chcp...
EDIT: Though may be better to use shortstrings...
Bart:
I found this, maybe helps:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit setdefaultcodepages; interface uses Windows; implementation Const LF_FACESIZE = 32; Type CONSOLE_FONT_INFOEX = record cbSize : ULONG; nFont : DWORD; dwFontSizeX : SHORT; dwFontSizeY : SHORT; FontFamily : UINT; FontWeight : UINT; FaceName : array [0..LF_FACESIZE-1] of WCHAR; end; { Only supported in Vista and onwards!} function SetCurrentConsoleFontEx(hConsoleOutput: HANDLE; bMaximumWindow: BOOL; var CONSOLE_FONT_INFOEX): BOOL; stdcall; external 'kernel32.dll' name 'SetCurrentConsoleFontEx';var New_CONSOLE_FONT_INFOEX : CONSOLE_FONT_INFOEX; initialization writeln('SetDefaultCodepages unit initialization: DefaultSystemCodePage = ',DefaultSystemCodePage); {$ifdef DisableUTF8RTL} SetConsoleOutputCP(DefaultSystemCodePage); SetTextCodepage(Output, DefaultSystemCodePage); {$else} SetConsoleOutputCP(cp_utf8); SetTextCodepage(Output, cp_utf8); {$endif} FillChar(New_CONSOLE_FONT_INFOEX, SizeOf(CONSOLE_FONT_INFOEX), 0); New_CONSOLE_FONT_INFOEX.cbSize := SizeOf(CONSOLE_FONT_INFOEX);// New_CONSOLE_FONT_INFOEX.FaceName := 'Lucida Console'; New_CONSOLE_FONT_INFOEX.FaceName := 'Consolas'; New_CONSOLE_FONT_INFOEX.dwFontSizeX := 8; New_CONSOLE_FONT_INFOEX.dwFontSizeY := 16; SetCurrentConsoleFontEx(StdOutputHandle, False, New_CONSOLE_FONT_INFOEX);end.
I rember being able to output all sorts of UTF-8 strings on the console using this.
Bart
wp:
--- Quote from: tetrastes on March 03, 2024, 10:46:03 pm ---
--- Quote from: wp on March 03, 2024, 10:24:39 pm ---
--- Quote from: tetrastes on March 03, 2024, 10:01:24 pm ---Try this [...] with different CPs in SetConsoleOutputCP, and with and without LazUTF8.
--- End quote ---
A very non-Pascal-ish way to use WriteLn...
--- End quote ---
You mean using pchar(s)? But thus we can output utf8 without forcing users to chcp...
--- End quote ---
Yes, certainly. But why can't WriteLn do it by itself without forcing me to type-cast the string to PChar?
wp:
Ah, SetTextCodePage was missing - that's the solution. Thanks, Bart.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program utf8_console;{$mode objfpc}{$H+}{$R *.res} // Do not remove. And check "Use manifest resouce" and "ANSI codepage is UTF8" in project optionsuses windows;var s1, s2, s3: String;begin SetConsoleOutputCP(CP_utf8); // important SetTextCodepage(Output, cp_utf8); // important s1 := '春夏'; s2 :='秋冬'; s3 := s1 + s2; WriteLn(s1, ' ', s2, ' ' , s3); Readln;end.
Output (with code page of console window set to 1252):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---春夏 秋冬 春夏秋冬
Bart:
--- Quote from: wp on March 03, 2024, 11:03:14 pm ---Ah, SetTextCodePage was missing - that's the solution. Thanks, Bart.
--- End quote ---
It's not my code.
It was posted here on the forum some years ago.
Bart
Navigation
[0] Message Index
[#] Next page
[*] Previous page