Replace a string in var

Good morning everyone,
I couldn’t find any solution, because of that now we don’t have storeEval as a exist command in Kantu.
So, does enyone know how to replace one string inside variable?
BTW it is not a problem with string but with any char inside of variable.
I store date in var “10.09.2020” and I want to delete every single dot and my output should be: “10092020”.
I tried many solutions but finally I get same error:

  • [error]

Line 24: Error in executeScript_Sandbox code: unexpected token: numeric literal

Part of the code:

  "Command": "store",
  "Target": "${!COL4}",
  "Value": "Myvar"
},
{
  "Command": "executeScript_Sandbox",
  "Target": "\"var str = ${Myvar}; return str.replace(/./g,\\\" \\\");\"",
  "Value": ""

In the next step I try to fill next field by the replaced date, must be string.

Can you help me with that?

1 Like

For someone who wants to fix his own problem, I’ve done it. It was easier than I expected:
check this out:)
“Command”: “executeScript_Sandbox”,
“Target”: “return ${Myvar}.replace(/(\.)/gm, “”)”,
“Value”: “Myvar”

This replaces every dot from var to any other char :slight_smile:

Admin can close the thread, thank you:)

1 Like

This is the solution

Code:

{
  "Name": "Replace",
  "CreationDate": "2020-9-11",
  "Commands": [
    {
      "Command": "store",
      "Target": "10.09.2020",
      "Value": "MyValue"
    },
    {
      "Command": "echo",
      "Target": "${MyValue}",
      "Value": "#shownotification"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var mystring = ${MyValue}; var replaced = mystring.replace(/\\./g,''); return replaced",
      "Value": "MyValue"
    },
    {
      "Command": "echo",
      "Target": "${MyValue}",
      "Value": "#shownotification"
    }
  ]
}

Log

[status]

Playing macro Replace

[info]

Executing: | store | 10.09.2020 | MyValue |

[info]

Executing: | echo | ${MyValue} | #shownotification |

[echo]

10.09.2020

[info]

Executing: | executeScript_Sandbox | var mystring = ${MyValue}; var replaced = mystring.replace(/./g,’’); return replaced | MyValue |

[info]

Executing: | echo | ${MyValue} | #shownotification |

[echo]

10092020

[info]

Macro completed (Runtime 1.37s)

1 Like

I am linking it to Selenium IDE string operations with executeScript_Sandbox