string testURL = 'www.google.com/just test'
StringBuilder emailBody = new StringBuilder();
emailBody.Append("<tr>");
emailBody.Append("<td> Just the URL </td>");
emailBody.Append("<td> String with href property </td>");
emailBody.Append("</tr>");
emailBody.Append("<tr>");
emailBody.Append("<td>" + testURL + "</td>"); // it displays: www.google.com/just test
emailBody.Append("<td> <a href=" + Uri.EscapeDataString(testURL) + ">" + name + "</a> </td>");
// the href property displays only: www.google.com/just
emailBody.Append("</tr>");
我该如何做到这一点?我Uri.EscapeDataString()方法用href属性中的空格链接
这里http://stackoverflow.com/questions/1517586/how-do-看看i-replace-all-spaces-with-20-in-c-sharp – Mark
此外,您编写的代码不会编译。你在'href =“Uri.EscapeDataString'之间缺少一个'+',你的testURL字符串应该被'''包围,而不是''' –
Ohhh。我的错。当你看到接受的答案时,就会发生这种情况,但是你考虑的是最多的评论。我应该删除这个问题吗? –