【问题标题】:html generated from a web service adding backslashes into the code从 Web 服务生成的 html 在代码中添加反斜杠
【发布时间】:2019-09-15 13:19:04
【问题描述】:

我正在从 Web 服务生成 html 代码。该 html 包含一个表格和表格的行和列。输出不如预期。它在每个斜杠上加上一个反斜杠。像下面这样。

<table class='table-fill'>
<thead>
<tr>
<th class='text-left' colspan=4>Patient name:A<\/th>
<\/tr>
<\/thead>
<tbody class='table'>
<tr>
<td class='text-left'>Age:<\/td>
<td class='text-left'>65<\/td>
<td class='text-left'>Blood Pressure:<\/td>
<td class='text-left'>142\/90 mmHg<\/td>
<\/tr>
<\/tbody>
<\/table>

我尝试了 htmlencode,但反斜杠仍然存在。请帮忙

我使用的代码是

string htmlstring = "<br><br><br><br>";
                        htmlstring = htmlstring + "<table class='table-fill'>";
                        htmlstring = htmlstring + "<thead>";
                        htmlstring = htmlstring + "<tr>";
                        htmlstring = htmlstring + "<th class='text-left' colspan=4>Patient name:" + c.Patname +"</th>";
                        htmlstring = htmlstring + "</tr>";
                        htmlstring = htmlstring + "</thead>";
                        htmlstring = htmlstring + "<tbody class='table'>";
                        htmlstring = htmlstring + "<tr>";
                        htmlstring = htmlstring + "<td class='text-left'>Age:</td>";
                        htmlstring = htmlstring + "<td class='text-left'>" + c.Age + "</td>";
                        htmlstring = htmlstring + "<td class='text-left'>Blood Pressure:</td>";
                      htmlstring = htmlstring + "<td class='text-left'>" + c.Bpr + "</td>";

【问题讨论】:

  • 您遇到的问题是因为 C# 生成文字“/”需要使用转义键字符“\”。你能展示你是如何实现你的方法的吗?

标签: c# html visual-studio web-services


【解决方案1】:

找到答案

答案很简单:字符串中没有反斜杠!

您看到的是 Visual Studio 调试器对字符串的表示。由于您使用的是 C#,因此它会显示带有转义字符的字符串,您需要在 C# 代码中将该值键入为字符串文字。但这些转义字符实际上并不是字符串的一部分。

【讨论】:

    猜你喜欢
    • 2022-12-03
    • 2017-05-12
    • 2013-12-01
    • 2016-11-21
    • 1970-01-01
    • 2018-08-05
    • 2015-10-23
    • 1970-01-01
    • 2019-07-04
    相关资源
    最近更新 更多