Search code examples
javahtmlescapingquoteshtml-escape-characters

How can I escape this HTML string within Java?


I am having trouble with adding the buttonClassvariable into the class attribute. How can I escape the double and single quotes here?

 String buttonClass= changed ? "changeButton" : "dontChangeButton";
 button.append("<input id='" + id + "' type='button' value='" + buttonValue + "' class='" + buttonClass
 + "' ui-button ui-widget' />");

Solution

  • You can use backslash for escaping character, or post the string on this website and let it do the work for you: http://www.freeformatter.com/java-dotnet-escape.html