I got a couple of response from a json which includes curly braces such as ${title} or {title} How can I replace these vaules with values I preselected?

For example:

jsonString = '{title}.2019.mkv'
jsonString2 = '${title}.2019.mkv'

How can I replace the field in those Strings with values I preselected like:

var title = 'Avengers'

Maybe I should just use regex or is there a better way?


Solution 1: Hanna Nosova

In case you need to replace part of the string you can use

'{title}.2019.mkv'.replaceFirst('{title}', 'Avengers')

Link to documentation