Jump to content
Sign in to follow this  
ChrisL

Is there a better way with SREReplace?

Recommended Posts

ChrisL

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

Share this post


Link to post
Share on other sites
ResNullius

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.