◆快速截取字符串后再替换
现在有一串字符串,大概有1000位左右.
现在需要截取里面从 " <loop> "至 " </loop "> 当中的字符串,并替换成
"loopstr "
谢谢..
字符串大概如下:
*****************
******************
<loop> ****************
**********
</loop>
**************
vbman2003,两位星星的高手给我以下这段代码:
dim s as string
s= "你的字符串 "
s=replace(s, " </loop> ", " <loop> ")
s=split(s, " <loop> ")(1)
这段代码可以把当中的字符串截取出来,
现在需要把截取后的字符串替换成 "loopstr "再还原回去.
这要怎么改呀,谢谢..
[解决办法]
dim s as string
s= "你的字符串 "
dim pos1 as integer,pos2 as integer
pos1=instr(s, " <loop> ")
pos2=instr(s, " </loop> ")
s=left(s,pos1-1) & "loopstr " & mid(s,pos2+len( " </loop> "))
[解决办法]
首先那个方法是找到loop之间的字符,你没有loop自然就出错了。是逻辑的问题
dim s as string
s= "你的字符串 "
s=replace(s, " </loop> ", " <loop> ")
s=split(s, " <loop> ")(1)
if s= " " then msgbox "Nothing found "
[解决办法]
Private Sub Command1_Click()
Dim s As String
Dim x() As String
s = Text1.Text
s = Replace(s, " </loop> ", " <loop> ")
x = Split(s, " <loop> ")
ReDim Preserve x(0 To 2) As String
s = x(0) & "loopstr " & x(2)
Text1.Text = s
End Sub