开发者

How to convert PAnsiChar to WideString or string?

How do I convert a PAnsiChar variable to WideString or t开发者_JS百科o string?


You simply assign one variable to another and let the Delphi compiler do all the conversion for you:

var
  p: PAnsiChar;
  s: string;
  w: WideString;
....
s := p;
w := p;

If you want to convert in the other direction, and restricting the discussion to Delphi 7 for which Char, PChar, string are all ANSI data types you would use the following:

PAnsiChar(s);
PAnsiChar(AnsiString(w));

The casts are needed when going in this direction and in the case of the WideString the data must be explicitly converted from Unicode to ANSI before asking for a null-terminated C string pointer.


var
  s: AnsiString;
  w: WideString;
  p: PAnsiChar;
...
  s := p;
  w := WideString(s);


s:PAnsiChar;

WideString(AnsiString(s));

Or on unicode Delphi's you probably want:

String(AnsiString(s));


Look for StrPas function in docs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜