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

2018-06-17 17:14:26来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

方法一:
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->

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:破解Windows屏幕保护admin888

下一篇:让VB使用彩色及动画光标的方法