Escaping Groovy Scripts

Hi All,

I am new with Katalon Studio and need verify.
Is this katalon using native Groovy for scripting the test case.

Why do I need backslash with 4x for escaping character to replace.
This is a String to need verify read by excel:
“Pemesanan terverifikasi.\nLangsung bayar, yuk!”

I need replace this string for new line or “\n”

and for scripting i use.
str.replace(“\\n”, “”)

if i use two times/2x got an error and in Katalon can’t replace.
But if i using the other tools like Intellij is just use two backslash.

Thank you

@irfaan.hibatullah, can you provide an example script for us to test it? And to answer your first question, yes, Katalon does use native Groovy.

Try this:

str.replace(/\n/, '')

/\n/ is a regular expression.
'' is a pair of single quotes.

I use this every day so I know it works fine.

2 Likes

Hey Rus,

Oke thank you for this solution.

But i’am curious what happen in Groovy Katalon when I trying to escaping a new line? why is it different with another groovy compiler in other tools

Sorry, I don’t understand your question.

this is chen.

when i’am trying code groovy with intellij, this doesn’t need to put 4x backslash “\\”

Hey Russ,

After i put the regex, this solution is not working

I don’t know what to say – the code works. See also…

The context is different, but the essential parts are the same:.