PDA

View Full Version : Replace method not replacing


oracleguy
03-18-2003, 02:15 AM
I have this bit of code and I use the replace method and it doesn't seem to do anything. I know the search string is in there but it doesn't seem to work.

Here is the code:

Function QuickCode (strBlock1, strBlock2)
Dim rex, vntExp, strData, aryData(90), exp2, intX, strTemp
strData=strBlock1 & strBlock2
Set rex = New RegExp
'First search for images
With rex
.Pattern="\[img\]\w+.\w+\[/img\]"
.IgnoreCase = True
.Global = True
End With
Set vntExp=rex.Execute(strData)
If vntExp.Count>0 Then
'There is image code
intX=0
For Each exp2 in vntExp
aryData(intX) = mid(strData,(exp2.FirstIndex),(exp2.Length))
aryData(intX) = mid(aryData(intX),instr(aryData(intX),"]")+1)
aryData(intX) = mid(aryData(intX),1,instr(aryData(intX),"[/")-1)
strTemp="<img src=""" & aryData(intX) & """ alt="""" />"
Replace strData,strTemp,mid(strData,(exp2.FirstIndex),(exp2.Length+1))
intX=intX+1
Next
End If

QuickCode=strData
End Function

The data that it is processing is : "This is a test. [ img]image.gif[ /img]"

(spaces in img tag to prevent vB code parsing)

What am I missing? Why doesn't it replace like it should?

david7777
03-18-2003, 07:24 AM
Syntax for Replace:

Replace(string,find,replacewith[,start[,count[,compare]]])

So, you need the syntax of:
Replace(String to be searched, What you will replace, What you will replace with)

So your current syntax seems wrong if i am not mistaken...

I think you need something like:

Replace(strData,mid(strData,(exp2.FirstIndex),exp2.Length+1)), strTemp)


That means that you will look through strData, search for whatever is in mid(strData,(exp2.FirstIndex),exp2.Length+1)), and replace all the occurances of that in strData with strTemp.

Hope that helped
:cool:

oracleguy
03-19-2003, 12:03 AM
Yeah that was it... thanks again :thumbsup: