UBB problem

freakshow54
12-10-2002, 05:56 PM
A program I'm working on uses something similar to UBB. I'm having a problem with replacing some text. I want to include a tag like this...
{url=http://www.anyurl.com}link text{/url}

I can't figure out how to pull the url out though. I need to turn that into...
<a href="http://www.anyurl.com">link text</a>
Any suggestions?

Termor
12-10-2002, 08:18 PM
Here was some brute force type code I just whipped up. Obviously this has no error or exception checking, but it should hopefully give you something to play with. You'll want to loop for multiple occurances of urls.

Dim strText As String
Dim lngStart As Long
Dim lngFinish As Long
Dim lngLen As Long
Dim strBuf As String
Dim lngDiv As Long
Dim strNew As String

strText = "something {url=http://www.anyurl.com}link text{/url} something"

lngStart = InStr(strText, "{url=")
lngFinish = InStr(lngStart + 5, strText, "{/url}")
lngLen = (lngFinish + 6) - lngStart

strBuf = Mid$(strText, lngStart + 5, lngLen - 11)
lngDiv = InStr(strBuf, "}")

strNew = Left$(strText, lngStart - 1) _
& "<a href=""" & Left$(strBuf, lngDiv - 1) _
& """>" & Right$(strBuf, Len(strBuf) - lngDiv) & "</a>" _
& Right$(strText, Len(strText) - (lngFinish + 5))

Debug.Print strNew

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum