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 获取网络文件大小

Delphi strutils.dupestring - 反复字符串

Delphi在设计时设置tstringgrid控件各列的列宽

Delphi获取access中的表名代码

Delphi 中的常用事件

Delphi程序在win7 win8 win10下自动请求以管理员身份运行

Delphi 多函数形式的多线程同步-线程执行顺序

Delphi 如何产生输出一个变形的图形及文字

Delphi datasnap使用ipv6

Delphi木马生成技术

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



打赏

取消

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

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

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

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

评论

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