Delphi delphi Copy,Pos,Delete Win Api 版


本文整理自网络,侵删。

 


  function StrStrA(lpFirst, lpSrch: PAnsiChar): PAnsiChar; stdcall; external 'shlwapi.dll' name 'StrStrA'; 
  function StrNCatA(lpFirst, lpSrch: PAnsiChar; cchMax: Integer): PAnsiChar; stdcall; external 'shlwapi.dll' name 'StrNCatA'; 
   
  function Pos(lpSrch, lpFirst:PAnsiChar):Integer; 
  begin 
    Result := DWORD(StrStrA(lpFirst,lpSrch)) - DWORD(lpFirst) + 1; 
  end; 
   
  procedure Delete(lpszStr: PAnsiChar; index, count: Integer); 
  var 
    Len :Integer; 
  begin 
    Len  := lstrlenA(lpszStr); 
    if len = count then 
    begin 
     lstrcpyA(@lpszStr[index - 1], @lpszStr[index + count -1]); 
     ZeroMemory(@lpszStr[index -1], index + count); 
    end else begin 
     lpszStr[index - 1] := #0; 
     StrNCatA(lpszStr, @lpszStr[index + count - 1], Len); 
    end; 
  end; 
   
  function Copy(lpszStr:PAnsiChar; index, count:Integer):PAnsiChar; 
  begin 
    Result := GetMemory(count - index); 
    lstrcpynA(Result, @lpszStr[index -1], count); 
  end; 
  //----------------------------------例子 
  procedure TForm1.Button1Click(Sender: TObject); 
  var 
    buf, tmp: PAnsiChar; 
    i:Integer; 
  begin 
   buf := GetMemory(10); 
   ZeroMemory(buf, 10); 
   StrCopy(buf, 'http://www.lovehuai.cn/'); 
   i   := Pos('u', buf); 
   Delete(buf, i, 2); // 执行后buf = http://www.loveai.cn/ 
   tmp := Copy(buf, 1, 5); 
   Edit1.Text := buf  +  ' pos:' + IntToStr(i) + ' tmp:' + tmp; 
  end; 

相关阅读 >>

Delphi显示 jpg、png、gif 图片及 gif 动画

Delphi 判断特定字符是为单字节还是双字节

Delphi 清空某个form的控件内容,用tag来判断

Delphi驱动结束进程

Delphi firedac 下的 sqlite [2] - 第一个例子

Delphi pascal 单元文件的特殊定义格式

Delphi 临时文件路径(支持安卓、ios)

Delphi program name、process id、window handle、process handle 的转换函数

Delphi unigui 路径

Delphi tadodataset 中文使用说明

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...