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

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

函数原型:

StrPas

1
2
3
4
5
6
7
8
9
10
11
{$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 

1
2
3
4
5
6
7
8
9
10
11
{$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;
1
2
3
4
5
6
7
8
9
10
11
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 使用示例:

1
2
3
4
5
6
7
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  更新时间:

 

posted on   滔Roy  阅读(3214)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报

导航

点击右上角即可分享
微信分享提示