Link to home
Start Free TrialLog in
Avatar of wantime
wantime

asked on

Delphi utf8: save string to array

hi,

that's say there are two variable "buffer" and "s"

var buffer: array[0..127]of char;
s: string;

s := 'prüfen';

how do i save variable s to buffer as utf8 format?

thanks,

wantime
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

try

procedure TForm1.Button1Click(Sender: TObject);
var
  S: UTF8String;
  ar: array[0..127] of AnsiChar;
begin
  S := 'prüfen';

  FillChar(ar, SizeOf(ar), 0);

  Move(Pointer(s)^, ar, Length(s) * SizeOf(Char));

  ShowMessage(UTF8String(ar));
end;
Avatar of wantime
wantime

ASKER

thanks.

btw, what is different between

array[0..127] of Char

and

array[0..127] of AnsiChar

?
when using Delphi 2009 +,  Char is WideChar
Avatar of wantime

ASKER

if Char is WideChar, which change should be made in the solution? I know that the space of buffer will be doubled, but i have not yet found the way to resolve it, the output in delphi2009 is not 'prüfen' but some chinese symbol.


ASKER CERTIFIED SOLUTION
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial