0

I have a string that may contains the next characters '&' and/or '<' and/or '>'

for each one of these characters I need to replace it with Charater ref in html :

  • '&' -> "&amp ;"
  • '<' -> '&lt ;'
  • '>' -> '&gt ;'

I have implimented this using the following code and it's working:

if( _.contains(note,"&")){
    note = note.replace("&","&amp;");
}if( _.contains(note,"<")){
    note = note.replace("<","&lt;");
}if( _.contains(note,">")){
    note = note.replace(">","&gt;");
                }
return note;

is there a shorter way to impliment this ?

R0b0t0
  • 390
  • 6
  • 20

0 Answers0