delphi delphi Copy,Pos,Delete Win Api 版  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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; 


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.043178081512451 seconds