Tuesday, May 30, 2017

Java - escape double quotes and slashes in html

class Main {
  public static void main(String[] args) {
    String str = "<div name=\"hey\">content</div>";
System.out.println(str);
    
str = str.replace("\"", "\\\"") ;   
str = str.replace("/", "\\/") ;   

System.out.println(str);
  }
}

No comments:

Blog Archive