rameshsmw (1) [Avatar] Offline
#1
hi,

i have a method in groovy which gets a parameter as string. the string has a value "This is to test $test_id. now i want to replace the $test_id with "Missing". what is the exact escape character for $.

Note: the string which comes as a parameter has the $ symbol.

def static String replace(String footerText, String replace)
{
footerText = footerText.replaceAll("$",replace);

}

in the above method the string footertext will hold "This is to test $test_id". now i want to replace $test_id with "missing". but the above replace statement doesn't work.

can anyone tell the escape character for $ for the above scenario?

thanks
Mittie (397) [Avatar] Offline
#2
Re: escape character for $ in groovy
I'm not sure that I have understood your intention, but you can do

def s = 'This is to test $test_id'
s.replaceAll('\$test_id', 'missing')

cheers
Dierk