Delphi 字符串函數 StrPas和StrPCopy - String轉Char / Char 轉 String


Delphi StrPas和StrPCopy  - String轉Char / Char 轉 String

函數原型:

StrPas

{$IFNDEF NEXTGEN}
function StrPas(const Str: PAnsiChar): AnsiString;
begin
  Result := Str;
end;
{$ENDIF !NEXTGEN}

function StrPas(const Str: PWideChar): UnicodeString;
begin
  Result := Str;
end;

 StrPCopy 

{$IFNDEF NEXTGEN}
function StrPCopy(Dest: PAnsiChar; const Source: AnsiString): PAnsiChar;
begin
  Result := StrLCopy(Dest, PAnsiChar(Source), Length(Source));
end;
{$ENDIF !NEXTGEN}

function StrPCopy(Dest: PWideChar; const Source: UnicodeString): PWideChar;
begin
  Result := StrLCopy(Dest, PWideChar(Source), Length(Source));
end;
function StrLCopy(Dest: PWideChar; const Source: PWideChar; MaxLen: Cardinal): PWideChar;
var
  Len: Cardinal;
begin
  Result := Dest;
  Len := StrLen(Source);
  if Len > MaxLen then
    Len := MaxLen;
  Move(Source^, Dest^, Len * SizeOf(WideChar));
  Dest[Len] := #0;
end;

  

Delphi 使用示例:

var
   Msgs:array[0..255] of Char;
   Str:string;
begin
    StrPCopy(Msgs,Memo1.Text);   // j將Memo1.text的值復制到Msgs
    Str:=StrPas(Msgs);   //將Msgs的值輸出為字符串類型
end

  

 

 

 

創建時間:2020.06.04  更新時間:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM