Hej!
Någon som har en färdig lösning på mitt problem:
Tänk er ett textsträng:
strText = "<DIV CLASS="bild">Massa text och en <A HREF="images/bild_stor.gif"><IMG SRC="images/bild.gif" ALT="bild"></A> bild som blir en stor bild om man klickar på den.</DIV>"
Jag vill nu göra en Replace på den typ
Replace(strText,"bild","<B>bild</B>")
Men jag vill inte att orden bild innanför <> ändras för då blir ju sökvägen fel.
Jesper TMedlem sedan nov. 20017 144 inlägg Detta är en class som Patrik B har gjort har jag för mig:
<%
'Denna klass markerar upp sökta ord
Class MarkWord
Private m_intWordCount ' As Integer
Public Property Let WordCount(ByVal iWordCount) ' As Integer
m_intWordCount = iWordCount
End Property
Public Property Get WordCount
WordCount = m_intWordCount
End Property
Public Function MarkSearchedWords(ByVal sContent, ByVal sSearchedWord) ' As String
DIm objRegExp
Dim Matches
Dim Match
Set objRegExp = New RegExp
objRegExp.Global = True
objRegExp.IgnoreCase = true
objRegExp.Pattern = "" & Replace(sSearchedWord,".","\.")
Set Matches = objRegExp.Execute(sContent)
'## -- how many matches have we found --
WordCount = Matches.Count
'## -- mark every match with bold --
For Each Match In Matches
sContent = Replace(sContent,Match,"<b>" & Match & "</b>")
Next
Set matches = Nothing
Set objRegExp = Nothing
MarkSearchedWords = sContent
End Function
End Class
%>
Det ser ju bra ut, men vad är skillanden på det och Replace()?
Problemet kvarstår väll att den byter ute även innanför taggar (<>)