How do I escape quotes in my string?

From the Asset Store
Escape the jet fighter and survive as long as you can!
  • I have a string Global Variable called help_url that looks like this "https://www.example.com/site#1" (the exact site URL changes during gameplay). Construct forces me to put double quotes around it since it has a # character.

    Users are supposed to be able to click on a UI button and then it takes them to the help_url in a new window. Now I am setting up the Browser action for when a user clicks on the button, which means I have to strip out those double quotes, so I'm trying to use:

    RegexReplace(help_url,"/["']/","","")

    But Construct rejects this because it wants me to close the double quoted string in the REPLACE spot. I'm not great at REGEX, but I've also tried approaching from a different angle with my URL using

    RegexMatchAt(help_url, "/[a-zA-Z0-9]*-[a-zA-Z0-9]*/", "", 0)

    But that doesn't work either (the page opens to about:blank). Can anyone tell me what I'm doing wrong or suggest a better way?

  • Construct forces me to put double quotes around it since it has a # character.

    No, it doesn't. You don't need to add any quotes.

    And then if you want to replace #1 with something else, you can use replace(s, "#1", "SomethingElse") expression. It's much easier than RegexReplace.

  • I should have clarified: you're right that when I set up the Global variable the first time I can include a hashtag in the string, but when I try to use the "Set Value" action, I cannot change the global variable string to a string with a hashtag without putting quotes around it. See the image here.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • In this case you need to put the string in quotes, but they are not part of the string, so you don't need to replace them with RegexReplace.

    Set clue_url to "https://www.example.com/site#1"
    Set clue_url to replace(clue_ulr, "site#1", "somethingelse")
    
  • Ah you're right! I guess I shouldn't have assumed the quotes would become part of the string. Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)