jim wrote:
I've got a page of text which I am assigning to a string. Within this
page there are special tags e.g. lots of text....<ti>dogs</ti>..lots
more text....<ti>this is a cat</ti> etc.. So I've got a long string
interspersed with these tags. Now what I need to do is get a list of
the words/phrases that are within these tags. So in my list I would
get dogs, this is a cat etc..
I've tried a combination of mid, instr and replace and got it sort of
working but there's got to be a more efficient way of doing it.
Possibly using regular expressions?
You can use regular expression matching for that as long as your tags
are not nested:
<%@ Language="VBScript" %>
<%
Option Explicit
Dim Text, Result, ResultText
Text = "lots of text....<ti>dogs</ti>..lotsmore text....<ti>this is a
cat</ti>"
Function SearchTextFor (Text, TagName)
Dim TagRegExp, Match, Matches
Set TagRegExp = New RegExp
TagRegExp.Pattern = "<" & TagName & ">" & "(.*?)" & "</" & TagName & ">"
TagRegExp.Global = True
Set Matches = TagRegExp.Execute(Text)
Dim Results()
ReDim Results(Matches.Count)
Dim CurrentIndex
CurrentIndex = 0
For Each Match in Matches
Results(CurrentIndex) = Match.SubMatches(0)
CurrentIndex = CurrentIndex + 1
Next
SearchTextFor = Results
End Function
Result = SearchTextFor(Text, "ti")
For Each ResultText in Result
Response.Write "<p>" & ResultText & "</p>" & VbCrLf
Next
%>
--
Martin Honnen
http://JavaScript.FAQTs.com/