Reputation: 169
I have the following code snippet and i am trying add string demoString to href.
String demoString = "/helio/demo";
String demoStrUrl = "<a href=demoString ><h3 class="+"demoDetails" +">Details</h3></a>"
Upvotes: 0
Views: 303
Reputation: 15418
First escape the quote of demoString:
String demoString = "\"/helio/demo\"";
Then add it to demoStrUrl
using +
operator:
String demoStrUrl = "<a href="+demoString+" ><h3 class.....
To facilitate with escaping HTML you can look into the apache commons StringEscapeUtils
class.
Upvotes: 0
Reputation: 62864
Simply:
String demoString = "/helio/demo";
String demoStrUrl = "<a href=\"" + demoString + "\"><h3 class=\"demoDetails\">Details</h3></a>";
Note that if you want to add a "
sign within the String, you have to escape it with \
Upvotes: 1
Reputation: 19776
You have to append String variables as an object using +
only. Otherwise it would again be handled like a fixed String and not your defined variable.
String demoString = "/helio/demo";
String demoStrUrl = "<a href=\""+demoString+"\" ><h3 class=\"demoDetails\">Details</h3></a>";
Upvotes: 0