using jquery I need to recognize sequences of characters in a string and replace them with different strings.
starting from this:
var data = {
name : 'Brian',
surname : 'Logan',
city : 'London'
}
var msg = ' hello <name> <surname> from <city>! '
I need to process the string ‘msg’ to get this:
“Hello Brian Logan from London!”
I used a similar method when I worked in visual foxpro called ‘textmerge’, but I can not find a jquery function which does the same things.
Just pass a replacement function to
replace:You can call it like
msg.format(data).