### Replace between two Tokens

To replace text between two tokens, below an example on how to replace special HTML characters
between the two HTML tags CODE and /CODE.
' Replace special HTML characters between the CODE Tags. Note CODE must be In capital letters!
' Parameter String
' Returns Converted string
`Sub replaceInsideCode(s As String) As String
Dim su As String = s.ToUpperCase ' Set to uppercase
Dim ps As Int = su.IndexOf("`") ' Get index of `tag
If ps = -1 Then Return s
If ps > 0 Then ps = ps + 5 ' if found then adjust position
Dim pe As Int = su.IndexOf("`") ' get index of`
If pe = -1 Then Return s
Dim sorg As String = s.SubString2(ps, pe) ' get the text between the pre tags
Dim snew As String = sorg
snew = snew.replace("<", "<")
snew = snew.replace(">", ">")
snew = snew.replace("&", "&")
' Add more as required, like
' " = ", blank = euro = € etc.
Return s.replace("`" & sorg & "`", "`" & snew & "`")
End Sub`
'To replace all text within several CODE tags In a text use:
`Sub replaceCode(s As String) As String
Dim snew As String
Dim arr() As String = Regex.Split("`", s)
If arr.Length = 0 Then Return s
snew = ""
For i = 0 To arr.Length - 1
If arr(i).Contains("`") Then
snew = snew & "`" & replaceInsidePre2(arr(i))
Else
snew = snew & arr(i)
End If
Next
Return snew
End Sub`
`Sub replaceInsideCode2(s As String) As String
Dim ps As Int = 0 ' = su.IndexOf("`") ' get index of

     tag

      Dim pe As Int = s.IndexOf("

`") ' get index of
If pe = -1 Then Return s
Dim sorg As String = s.SubString2(ps, pe) ' get the text between the pre tags
Dim snew As String = sorg
snew = snew.replace("<", "<")
snew = snew.replace(">", ">")
snew = snew.replace("&", "&")
Return s.replace(sorg & "`", snew & "`")
End Sub#LINERB#

Changed: , Category: Strings, File: T6C255M1856.htm, ID: 1856