查看: 27|回覆: 0

Delphi 字符串函数 StrPas和StrPCopy - String转Char / Char 转 String

[複製鏈接]

1

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2009-2-5
發表於 2020-6-4 09:12:00 | 顯示全部樓層 |閲讀模式

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  更新时间:

 

回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部