Str.replace only replacing first instance

when using the str.replace function it only replaces the first instance found.

Any ideas?

|T|"“Screen%20Shot%202019-10-28%20at%204.32.19%20PM.png”"|

var str = ${t}; return str.replace("%20"," ")

End up with this

F ““Screen Shot%202019-10-28%20at%204.32.19%20PM.png””

RTFM!

Your function “replace” in Javascript is only ONCE without global modifier.
See https://www.w3schools.com/jsref/jsref_replace.asp

Example with global modifier in Kantu:

{
  "Name": "test-replace",
  "CreationDate": "2019-10-30",
  "Commands": [
    {
      "Command": "store",
      "Target": "Screen%20Shot%202019-10-28%20at%204.32.19%20PM.png",
      "Value": "t"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var str = ${t}; return str.replace(/%20/g,\" \");",
      "Value": "result"
    },
    {
      "Command": "echo",
      "Target": "${result}",
      "Value": ""
    }
  ]
}
1 Like

THANK YOU, that did the trick