3
String s=
    "<html>
    <head>
    <title>app</title>
    </head>
    <body bgcolor="pink">
    <div align="center"><img src="" width="900" height="100"/>
    </div>
    <h2 align="center">Welcome to your rewards program</h2>
    <table>
    <tr>
    <td><p>&nbsp;&nbsp;&nbsp;&nbsp;You now  have ongoing uninterrupted access to thousands of discounts all on your phone .Accessing great  savings just got so easier . You can search by category , by keyword and also search local with what around me. Select a merchant offer you like and present the coupon on your phone  at the time of settling your bill .  Some merchants only offer their services online and you will also be able  to click through to their online offerings . 
    GIN image</p></td>
    </tr>

    </table>
    </body>
    </html>";

我想将 html 数据添加到字符串中,但它给了我错误。我该如何解决这个问题?我使用了转义序列,但没有用。

谢谢

4

3 回答 3

4

试试这个

String s=
            "<html>"+
            "<head>"+
            "<title>app</title>"+
            "</head>"+
            "<body bgcolor=\"pink\">"+
            "<div align=\"center\"><img src=\"\" width=\"900\" height=\"100\"/>"+
            "</div>"+
            "<h2 align=\"center\">Welcome to your rewards program</h2>"+
            "<table>"+
            "<tr>"+
            "<td><p>&nbsp;&nbsp;&nbsp;&nbsp;You now  have ongoing uninterrupted access to thousands of discounts all on your phone .Accessing great  savings just got so easier . You can search by category , by keyword and also search local with what around me. Select a merchant offer you like and present the coupon on your phone  at the time of settling your bill .  Some merchants only offer their services online and you will also be able  to click through to their online offerings ."+ 
            "GIN image</p></td>"+
            "</tr>"+
            "</table>"+
            "</body>"+
            "</html>";
于 2013-05-30T10:35:52.613 回答
1
String s=
        "<html>"
        + "<head>"
        + "<title>app</title>"
        + "</head>"
        + "<body bgcolor=\"pink\">"
        + "<div align=\"center\"><img src=\"\" width=\"900\" height=\"100\"/>"
        + "</div>"
        + "<h2 align=\"center\">Welcome to your rewards program</h2>"
        + "<table>"
        + "<tr>"
        + "<td><p>&nbsp;&nbsp;&nbsp;&nbsp;You now  have ongoing uninterrupted access to thousands of discounts all on your phone." 
        + " Accessing great  savings just got so easier . You can search by category , by keyword and also search local with what around me. Select a merchant offer you like and present the coupon on your phone  at the time of settling your bill." 
        + " Some merchants only offer their services online and you will also be able  to click through to their online offerings ." 
        + " GIN image</p></td>"
        + "</tr>"
        + "</table>"
        + "</body>"
        + "</html>";
于 2013-05-30T10:38:01.833 回答
0

如果您使用的是 Eclipse IDE...

Eclipse 不支持多行字符串赋值。

如果您使用的是 eclipse 编辑器,那么 goto Windows -> Preferences -> Java -> Editor -> Typing 和 chackEscape text when pasting into a string literal

之后,您可以复制整个字符串值并再次过去。

于 2013-05-30T10:37:59.077 回答