공공 TEncoding.GetString()
메소드는 동적 배열을 지원하지만 대신 TEncoding.GetCharCount()
및 TEncoding.GetChars()
의 보호 PByte
과부하를 사용할 수 있습니다, 예를 들면 :
type
TEncodingHelper = class(TEncoding)
public
function GetString(Bytes: PByte; ByteCount: Integer): String;
end;
function TEncodingHelper.GetString(Bytes: PByte; ByteCount: Integer): String;
begin
SetLength(Result, GetCharCount(Bytes, ByteCount));
GetChars(Bytes, ByteCount, PChar(Result), Length(Result));
end;
var
S: string;
begin
S := TEncodingHelper(TEncoding.UTF8).GetString(PByte(@arr[index]), ByteCount);
end;
또는 :
type
TEncodingHelper = class helper for TEncoding
public
function GetString(Bytes: PByte; ByteCount: Integer): String;
end;
function TEncodingHelper.GetString(Bytes: PByte; ByteCount: Integer): String;
begin
SetLength(Result, Self.GetCharCount(Bytes, ByteCount));
Self.GetChars(Bytes, ByteCount, PChar(Result), Length(Result));
end;
var
S: string;
begin
S := TEncoding.UTF8.GetString(PByte(@arr[index]), ByteCount);
end;
어떤 델파이 버전? –
RAD Studio 2010 – miodrag