Java 创建带有连接的字符串

Java 创建带有连接的字符串,java,Java,我有下面要创建的字符串 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

我有下面要创建的字符串

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.
我正试图通过如下的连接来创建最终的字符串

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."
String X=“已包含所有搜索信息。”
即使这样也不行

请让我知道如何解决这个问题

这里我甚至对
<和>
标记感到困惑,而不仅仅是引号


谢谢

您需要转义要显示在字符串中的引号

String x = "<a target=\"...\" href=\"...\">...</a>";
String x=”“;
以下是我写的内容

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);
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.
包含所有搜索信息。

这是否回答了您的问题?

那么
这些字符应该可以。您是想从一些html中读取还是将其用于其他目的使用
String.format()
更好,可读性更好。
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);
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.