Delphi Char、Pchar 、String 相互转换
2021-01-15 02:13
标签:for mem isp mes 转换 sage pos highlight array Delphi Char、Pchar 、String 相互转换 1、String 与 PChar 转换 1.2 PChar转String 3种方式 2、String 与 Char 转换 2.2 String 转 Char 3、Char 与 PChar 转换 3.2.PChar 转 Char 创建时间:2021.01.13 更新时间: Delphi Char、Pchar 、String 相互转换 标签:for mem isp mes 转换 sage pos highlight array 原文地址:https://www.cnblogs.com/guorongtao/p/14270681.html
1.1 String转化成PChar 2种方式var
s:string;
p,p1:PChar;
begin
s:=‘Hi Delphi7‘;
p:=PChar(s); //
ShowMessage(p);
p1:=StrAlloc(Length(s)+1);
StrPCopy(p1,s);
ShowMessage(p1);
StrDispose(p1);
end;
var
s,s1,s2:string;
p:PChar;
begin
s:=‘Hi Delphi7‘;
p:=PChar(s); //ShowMessage(p);
s1:=p; //ShowMessage(s1);
s2:=StrPas(p); //ShowMessage(s2);
end;
2.1 Char转String var
c:array [0..11] of Char;
s:string;
begin
s:=StrPas(@c[0]); //使用StrPas函数获取数组的首地址 ShowMessage(s);
end;
var
s:string;
c:array of Char;
i:Integer;
begin
s:=‘Hi Delphi7‘;
SetLength(c,Length(s));
//Move(s[1],c[0],Length(s));//move 或 CopyMemory
CopyMemory(@c[0],PChar(s),Length(s));
for i:=Low(c) to High(c) do
begin
ShowMessage(string(c[i]))
end;
end;
3.1 Char 转 PCharvar
c:array [0..11] of Char;
p:PChar;
begin
c:=‘Hi Delphi7‘;
//p:=@c[0];
p:=PChar(@c[0]);
ShowMessage(StrPas(p));
end;
var
s:string;
p:PChar;
c:array of Char;
i:Integer;
begin
s:=‘Hi Delphi7‘;
p:=PChar(s);
SetLength(c,Length(s));
//Move(p^,c[0],Length(s));//move 或 CopyMemory
CopyMemory(@c[0],p,Length(s));;
for i:=Low(c) to High(c) do
begin
ShowMessage(string(c[i]))
end;
end;
下一篇:win10安装配置tomcat
文章标题:Delphi Char、Pchar 、String 相互转换
文章链接:http://soscw.com/index.php/essay/42052.html