delphi Berlin10.1 string、AnsiString及Tbytes等之间的转换

1.类型说明

 

Byte:Represents an 8-bit unsigned integer type.

[PByte:Is a pointer to a Byte.]

 

Char:Represents a word-sized (16-bits) character type

AnsiChar:Represents a byte-sized (8-bits) character type

WideChar:Represents a word-sized (16-bits) character type.

[PChar:Defines a null-terminated string]

[PAnsiChar:Defines a null-terminated ANSI string.]

 

String:Represents an alias for the generic UnicodeString type.

AnsiString:Represents a dynamically allocated string whose maximum length is limited only by available memory.

WideString:A null-terminated string of wide characters, with no reference counting.

[PString:Is a pointer to a String.]

[PAnsiString:Is a pointer to an AnsiString.]

 

TBytes:declares an array of Bytes.

 

2.指针

 

 1         var

 2           X, Y: Integer;  // X and Y are Integer variables

 3           P: ^Integer;     // P points to an Integer

 4         begin

 5           X := 17;      // assign a value to X

 6           P := @X;      // assign the address of X to P

 7           Y := P^;      // dereference P; assign the result to Y

 8         end;

 

type

  PInteger = ^Integer;

var

  R: Single;

  I: Integer;

  P: Pointer;

  PI: PInteger;

begin

  ...

  P := @R;

  PI := PInteger(P);

  I := PI^;

end;

 

3.一些点

 

SizeOf:Returns the number of bytes occupied by a variable or type.

Length:Returns the number of characters in a string or of elements in an array. 

Move:Copies bytes from a source to a destination. e.g.: Move(PChar(@arrBuf[0])^, LPChar^, aSectorNum * 512);

ByteLength:Returns the length of a given string in bytes.

GetBytes:Encodes a set of characters into a sequence of bytes

FillChar:Fills contiguous bytes with a specified value.

 

 

4.转换

 

TBytes -> PChar :     LPChar :=  PChar(LTBytes);

PChar -> TBytes:LTBytes := BytesOf(LPChar);

TBytes -> Array of AnsiChar:move(LTBytes[i],LArrayOfAnsiChar[k]);

Array of AnsiChar -> string:LString := StringOf(BytesOf(LArrayOfAnsiChar));

转载于:https://www.cnblogs.com/keynexy/p/5919962.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值