View Full Version : Replacing tags

01-07-2007, 08:33 PM
Hi everybody,

I would like to know how I can separate a special tag created by me from an info coming from database. For example:

if the text is

This is a test message. This point is the part where we get the link

How can I replace [link=default.asp] tag with <a href="default.asp"> tag???

01-08-2007, 11:37 PM
sText = "This is a test message. This point is the part where we get the link"
sText = Replace(sText,"","<a href=""default.asp"">")
sText = Replace(sText,"","</a>")

01-12-2007, 04:04 PM
Also look into bbcode scripts as they will give you an idea of using regex to parse the text into links.


' Common Regular Expression Function
Function ReplaceRegExp(strString, strPattern, strReplace)

Dim RE: Set RE = New RegExp

With RE
.Pattern = strPattern
.Global = True
ReplaceRegExp = .Replace(strString, strReplace)
End With

End Function

' Turn BBcode into HTML
Function BBCodeToHTML(strString)
strString = ReplaceRegExp(strString, "\]*)\]([^\[]*)\[/link\]", "<a href=""$1"">$2</a>")
BBCodeToHTML = strString
End Function

str = "hello there this is a [link=default.asp]link"
Response.Write BBCodeToHTML(str)