Jump to content

StringReplace in Array with variable with line break


 Share

Recommended Posts

Hello All

I searched about this on the forums, but nothing turned up - it is pretty specific.

I've got a script which opens a webpage, searches through it and gets information from fields. So far, so good.

After I found this information, I change to html source to highlight the information. Which works most of the time, with the following exception:

If the String contains an html line break (< br >), it will fail to do this correctly, when the StringReplace is being done in a loop.

Dim $aInfo[5]
        
$aInfo[0] = $sNhId
$aInfo[1] = $sNhName
$aInfo[2] = $sNhCode
$aInfo[3] = $sNhDDA
$aInfo[4] = $sNhASDA
                
For $sInfo in $aInfo
    If $sInfo <> "" Then
        $sHTML = StringReplace($sHTML, $sInfo, '<span style="background-color: #ffff00">' & $sInfo & '</span>')
    EndIf
Next

Let's say that $sNhASDA = "test<br>item", then after _IEBodyWriteHTML, the source will show as "<span style="background-color: #ffff00">test</span><br>item" and only the first line will be highlighted.

Testing this outside the loop, the following work correctly:

$sHTML = StringReplace($sHTML, $sNhASDA, '<span style="background-color: #ffff00">' & $sNhASDA & '</span>')
$sHTML = StringReplace($sHTML, $aInfo[4], '<span style="background-color: #ffff00">' & $aInfo[4] & '</span>')
$i=4
$sHTML = StringReplace($sHTML, $$aInfo[$i], '<span style="background-color: #ffff00">' & $aInfo[$i] & '</span>')

When changing the loop to For To Step, it fails as well.

Using a temporary variable, instead of adding the <span... in StringReplace fails as well.

I know I could easily work around this - but I'd like to know what is going on or if I'm missing something...

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...