Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy String with a '$' character in it

Mamta Verma October 25, 2018

I'm trying to store a password in a groovy string something like below:

 

def password = "g4!r1*h2$mv"

I get an error: Static type checking: the variable mv is undeclared, which is probably because it encounters a dollar after h2. Is there a way to include $ as part of the string?

 

Thanks In Advance

2 answers

0 votes
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 25, 2018

Hello @Mamta Verma

In groovy escaping characters with one \

def password = "g4!r1*h2\$mv"
0 votes
Tom Lister
Community Champion
October 25, 2018

Hi @Mamta Verma

try escaping characters with \\

e.g. "g4!r1*h2\\$mv"

Mamta Verma October 25, 2018

Tried it .. I still get the same error!

Tom Lister
Community Champion
October 25, 2018

Thats odd

have you tried Slashy string format

def str = $/g4!r1*h2\$$mv/$

or single quotes instead of double quotes

def str = 'g4!r1*h2\\$mv'

Mamta Verma October 26, 2018

Single Quotes is working.. thanks Tom

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events