Jump to content
Sign in to follow this  
sakej

need help with StringRegExpReplace

Recommended Posts

Hi.

Im trying to replace \ with / with this code

 Local $stringReplace="//something/something"

 Local $stringReplace2=StringRegExpReplace($stringReplace, '/', '\')

but this dosent work, all i get is a string that looks like that "somethingsomething".

Anyone?

Edited by sakej

Share this post


Link to post
Share on other sites

Hi @sakej:)
Is this what you were looking for?

Global $strString = "//something/moresomething/moremoresomething/"

ConsoleWrite("String before: '" & $strString & "'" & @CRLF & _
             "String after: '" & StringReplace($strString, "/", "\") & "'" & @CRLF)

 


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Hi.

you need to "escape" the "\" in your (one char) replace string:

Local $stringReplace="//something/something"
Local $stringReplace2=StringRegExpReplace($stringReplace, '/', '\\')
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $stringReplace2 = ' & $stringReplace2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

regards, rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Yes if you use regex you need to escape it.

If you just use stringreplace() you do not, and for this particular task the normal string replace is adequate as your not really demanding anything that needs regex.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...