简体   繁体   中英

Adding values in a string with html code

i want to put the values inside the >< , but i couldn't do it because the errors of the "" start appearing. Thanks!

string Nome = reader.GetString(1);
            string Tipo = reader.GetString(2);
            int Preco = reader.GetInt32(3);
            string Horario = reader.GetString(4);
            htmlStr += @"<div>
                        < img class=""imagem"" src=""imagens/comer/pino.jpg"">
                        <p class=""my_p""></p>
                        <p class=""my_p1""></p>
                        <p class=""my_p2""></p>
                        <p class=""my_p3""></p>
                        <p class=""morada""></p>
                        <div class=""row"" style=""margin-top: -7px"">
                            <button class=""btn_reser"" onclick=""location.href='registo.aspx';"" type=""button"">Reservar</button>
                        </div>
                    </div>";

Use \\" instead of "" and use string.Format() to insert strings into another string...

string p = "paragraph 0";
string p1 = "paragraph 1";
string p2 = "paragraph 2";
string p3 = "paragraph 3";
string p4 = "paragraph 4";

string htmlStr = string.Format("<div>" +
            "< img class=\"imagem\" src=\"imagens/comer/pino.jpg\">" +
            "<p class=\"my_p\">{0}</p>" +
            "<p class=\"my_p1\">{1}</p>" +
            "<p class=\"my_p2\">{2}</p>" +
            "<p class=\"my_p3\">{3}</p>" +
            "<p class=\"morada\">{4}</p>" +
            "<div class=\"row\" style=\"margin-top: -7px\">" +
                "<button class=\"btn_reser\" onclick=\"location.href='registo.aspx';\" type=\"button\">Reservar</button>" +
            "</div>" +
        "</div>", p, p1, p2, p3, p4);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM