加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在delphi中Char,PChar,PByte,Byte,String的相互转换示例

发布时间:2020-12-15 09:58:20 所属栏目:大数据 来源:网络整理
导读:var s:string; pc:pchar; pb:pbyte; ac:array[1..100] of char; ab:array[1..100] of byte; i:integer;begin s:='this is a test'; pc:=pchar(s);//string-pchar pb:=pbyte(pc);//pchar-pbyte for i:=1 to length(s) do begin ac[i]:=s[i];//string-arrary o
var
    s:string;
    pc:pchar;
    pb:pbyte;
    ac:array[1..100] of char;
    ab:array[1..100] of byte;
    i:integer;
begin
    s:='this is a test';
    pc:=pchar(s);//string->pchar
    pb:=pbyte(pc);//pchar->pbyte
          for i:=1 to length(s) do
            begin
               ac[i]:=s[i];//string->arrary of char
               ab[i]:=byte(s[i]);//string->arrary of byte
            end;

    s:=pc;//pchar->string
    s:=string(pb);//pbyte->string
    s:=c;//arrary of char->string;

end;
DELPHI里把STRING转来BYTE再转回STRING的方法或代码Byte是8位的,只能代表一个字符。所以应该只有在String只有一位时才能转。String只有一位那就是个Char所以用Ord()和Chr()两个函数就可以互相转。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读