Hello All,
Please Guide me how to replace all in string
i want to replace rep with " ".
getting the value of id is dynamically from payload.
var rep = "ID"+" "+id+"_";
msg.payload=s.replace(rep," ");
This is working for single message. when multiple message is getting it replace only 1st message i want to replace all messages.
please guide me how to replace all string.
thanks
I tried this also but not working in my condition
var rep = "UI"+""+UnitId+"_";
msg.payload=s.replace(/rep/g,' ')
var text = "UI" + "" + UnitId + "_";
msg.payload = text.replace(/rep/g,' ')
E1cid
5
You would need to create the the regex pattern using the constructor property
var patt = new RegExp(rep, "g");
msg.payload = s.replace(patt, " ");
https://www.w3schools.com/jsref/jsref_regexp_constructor.asp
1 Like
its working for me... Thank you
system
Closed
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.