2

At following String.replace line, lossLocation.state$ ,

the $ sign is removed after the replace,

i need to keep the $, as it is used in the variable.

 '{0}'.replace(
         '{0}'
       , 'categories.Country === \'$formData.lossLocation.state$\'.toUpperCase()')

It gives me

"categories.Country === '$formData.lossLocation.state'.toUpperCase()"

The expected outcome should be

"categories.Country === '$formData.lossLocation.state$'.toUpperCase()"

i've tried the following but still been removed when replace

state\$
devric
  • 3,555
  • 4
  • 22
  • 36

1 Answers1

2

As it states in String.prototype.replace(). To escape '$' in replacement content, you should use '$$' instead of '\$'.

So a proper way of constructing it would be

'{0}'.replace('{0}', 
    'categories.Country === \'$formData.lossLocation.state$\'.toUpperCase()'
        .replace(/\$/g, '$$$$')
)
Rannnn
  • 582
  • 4
  • 10