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; 

相关阅读 >>

sendmessage在结束进程上的使用

Delphi把域名转换成ip

Delphi fdconnection自动重连

Delphi adoconnection断线重连

Delphi访问mysql乱码问题

Delphi 实现软件版验证码

Delphi (user agent) of a twebbrowser

Delphi 获取指定当前目录下指定文件扩展名所有文件

Delphi 清除字符串两边空格或指定字符

Delphi 批量生成 a到z 字母

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



打赏

取消

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

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

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

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

评论

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