-1

I've the below string to be created.

The <a target="" href="http://google.com/search=xyz">xyz</a><a target="" href="http://google.com/search=xyz"><img src="http://google.com/small.gif" alt="" title="smallimage" border="0"></a> has all the search info.

I'm trying to do it as below.

String X = "The <a target="" href="http://google.com/search=xyz">xyz</a><a target="" href="http://google.com/search=xyz"><img src="http://google.com/small.gif" alt="" title="smallimage" border="0"></a> has all the search info."

But it is throwing me syntax error.

Here I've created another String named searchTerm as below.

String searchTerm = "Hello";

and i'm trying to create the final string by concatenation like below.

String X = "The <a target="" href="http://google.com/search="+searchTerm+"">xyz</a><a target="" href="http://google.com/search="+searchTerm+""><img src="http://google.com/small.gif" alt="" title="smallimage" border="0"></a> has all the search info."

and even this is not working.

please let me know how can i fix this.

Here i'm even confused about < and > tags, not only about the quotes

Thanks

user3872094
  • 3,269
  • 8
  • 33
  • 71

2 Answers2

2

You need to escape the quotes that you want to appear in the String.

String x = "<a target=\"...\" href=\"...\">...</a>";
hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
2

Here's what I wrote...

String s = "The <a target=\"\" href=\"http://google.com/search=xyz\">xyz</a><a target=\"\" href=\"http://google.com/search=xyz\"><img src=\"http://google.com/small.gif\" alt=\"\" title=\"smallimage\" border=\"0\"></a> has all the search info.";
System.out.println(s);

and here's the output I get....

The <a target="" href="http://google.com/search=xyz">xyz</a><a target="" href="http://google.com/search=xyz"><img src="http://google.com/small.gif" alt="" title="smallimage" border="0"></a> has all the search info.

Does this answer your question?

cher
  • 51
  • 3