Jump to content

Is there a better way with SREReplace?


Recommended Posts

I have this...

$str = "< > & ' """
    $str = StringReplace($str,"&","&amp;")
    $str = StringReplace($str,"<","&lt;")
    $str = StringReplace($str,">","&gt;")
    $str = StringReplace($str,"'","&apos;")
    $str = StringReplace($str,'"',"&quot;")
    
    Msgbox(0,"",$str)

Is there a better way with StringRegExpReplace() to replace all in 1 go I could only seem to do it the same as I would with StringReplcae() by doing 1 item at a time.

Edited by ChrisL
Link to comment
Share on other sites

Don't think so with SRE, but what about something like this:

Dim $aReplacements[2][5]=[["&","<",">","'",'"'],["&amp;","&lt;","&gt;","&apos;","&quot;"]]

For $i = 0 to UBound($aReplacements,2)-1
    $str = StringReplace($str,$aReplacements[0][$i],$aReplacements[1][$i])
Next

Msgbox(0,"",$str)
Edited by ResNullius
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...