把符串中的一子串替换为另一子串_VB.net_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

把符串中的一子串替换为另一子串

作者:黑客防线网安VB教程基地 来源:黑客防线网安VB教程基地 浏览次数:0

本篇关键词:LenDstAsByteOutPosEndIf
黑客防线网安网讯:方法一:  PublicFunctionFastReplace(SSrch$,SFind$,SRepl$)AsString    DimSrc()AsByte,Dst()AsByte,R()AsByte,F()AsByte  DimLenF&,LenR&,LenDst&,i&,j&,OutPos&    ConstCh...
方法一:
  PublicFunctionFastReplace(SSrch$,SFind$,SRepl$)AsString
  
  DimSrc()AsByte,Dst()AsByte,R()AsByte,F()AsByte
  DimLenF&,LenR&,LenDst&,i&,j&,OutPos&
  
  ConstChunkSize&=4096
  
  IfSSrch=""OrSFind=""ThenExitFunction
  
  Src=SSrch:F=SFind:R=SRepl
  LenF=UBound(F):LenR=UBound(R)
  LenDst=ChunkSize:ReDimDst(0ToLenDst-1)
  
  Fori=0ToUBound(Src)Step2
  
  Forj=0ToLenFStep2
  IfSrc(i j)<>F(j)ThenExitFor
  Nextj
  
  Ifj>LenFThen'Found
  
  Forj=0ToLenRStep2
  IfOutPos>=LenDstThen
  LenDst=LenDst ChunkSize
  ReDimPreserveDst(0ToLenDst)
  EndIf
  Dst(OutPos)=R(j):OutPos=OutPos 2
  Nextj
  
  i=i LenF-1
  
  Else
  
  IfOutPos>=LenDstThen
  LenDst=LenDst ChunkSize
  ReDimPreserveDst(0ToLenDst)
  EndIf
  
  Dst(OutPos)=Src(i):OutPos=OutPos 2
  
  EndIf
  Nexti
  
  ReDimPreserveDst(0ToOutPos-2):SSrch=Dst
  
  FastReplace=SSrch$
  
  EndFunction
  
  方法二:
  'SearchLineisinput,SearchForiswhattosearchfor,ReplaceWithisthereplacement
  
  FunctionsReplace(SearchLineAsString,SearchForAsString,ReplaceWithAsString)
  DimvSearchLineAsString,foundAsInteger
  
  found=InStr(SearchLine,SearchFor):vSearchLine=SearchLine
  Iffound<>0Then
  vSearchLine=""
  Iffound>1ThenvSearchLine=Left(SearchLine,found-1)
  vSearchLine=vSearchLine ReplaceWith
  Iffound Len(SearchFor)-1<Len(SearchLine)Then_
  vSearchLine=vSearchLine Right$(SearchLine,Len(SearchLine)-found-Len(SearchFor) 1)
  EndIf
  sReplace=vSearchLine
  
  EndFunction->

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-14501-1.html
网站维护教程更新时间:2012-04-03 01:07:53  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer