我正在使用 Aspose.Words 将 Word 文档转换为 HTML,最后转换为包含文档所有 HTML 的字符串。
我遇到的麻烦是更换"\"
.
这是我从文档中得到的字符串:
htmlString "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"Content-Style-Type\" content=\"text/css\" /><meta name=\"generator\" content=\"Aspose.Words for .NET 13.7.0.0\" /><title></title></head><body><div><p style=\"font-size:12pt; line-height:115%; margin:0pt 0pt 10pt\"><span style=\"color:#ff0000; font-family:Calibri; font-size:12pt; font-weight:bold\">Evaluation Only. Created with Aspose.Words. Copyright 2003-2011 Aspose Pty Ltd.</span></p><h2 style=\"font-size:13pt; line-height:115%; margin:10pt 0pt 0pt; page-break-after:avoid; page-break-inside:avoid\"><span style=\"color:#4f81bd; font-family:Cambria; font-size:13pt; font-weight:bold\">This is a header</span></h2><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 10pt\"><span style=\"font-family:Calibri; font-size:11pt\"> </span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 10pt\"><span style=\"font-family:Calibri; font-size:11pt\">Look at my awesome bulleted list.</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 10pt\"><span style=\"font-family:Calibri; font-size:11pt\"> </span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 18pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">1)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Option 1</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">a)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Sup Option A</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">b)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Sub Option B</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">c)</span><span style=\"font:7.0pt 'Times New Roman'\">       </span><span style=\"font-family:Calibri; font-size:11pt\">Sub Option C</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 18pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">2)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Option 2</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">a)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Sub Option A</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 54pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">i)</span><span style=\"font:7.0pt 'Times New Roman'\">        </span><span style=\"font-family:Calibri; font-size:11pt\">Sub </span><span style=\"font-family:Calibri; font-size:11pt\">Sub</span><span style=\"font-family:Calibri; font-size:11pt\"> Option </span><span style=\"font-family:Calibri; font-size:11pt\">i</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">b)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Sub Option B</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 54pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">i)</span><span style=\"font:7.0pt 'Times New Roman'\">        </span><span style=\"font-family:Calibri; font-size:11pt\">Sub </span><span style=\"font-family:Calibri; font-size:11pt\">Sub</span><span style=\"font-family:Calibri; font-size:11pt\"> Option </span><span style=\"font-family:Calibri; font-size:11pt\">i</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 10pt 54pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">ii)</span><span style=\"font:7.0pt 'Times New Roman'\">       </span><span style=\"font-family:Calibri; font-size:11pt\">Sub </span><span style=\"font-family:Calibri; font-size:11pt\">Sub</span><span style=\"font-family:Calibri; font-size:11pt\"> Option ii</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 10pt\"><span style=\"font-family:Calibri; font-size:11pt\"> </span></p><p style=\"border-bottom-color:#4f81bd; border-bottom-style:solid; border-bottom-width:0.5pt; font-size:11pt; line-height:115%; margin:10pt 46.8pt 14pt; padding-bottom:4pt\"><span style=\"color:#4f81bd; font-family:Calibri; font-size:11pt; font-style:italic; font-weight:bold\">This is another heading</span></p></div></body></html>" string
如您所见,它有一大堆 =\" 我需要删除所有 \'s 并将其替换为 String.Empty。
这是我正在使用的代码:
string htmlString = doc.ToString(SaveFormat.Html);
string text = htmlString.ToString().Replace(@"\", string.Empty);
但是,当我将鼠标悬停在整个字符串上text
或添加手表时,仍会显示所有. 我在这里做错了什么?text
\'s
这是文本的监视值:
text "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"Content-Style-Type\" content=\"text/css\" /><meta name=\"generator\" content=\"Aspose.Words for .NET 13.7.0.0\" /><title></title></head><body><div><p style=\"font-size:12pt; line-height:115%; margin:0pt 0pt 10pt\"><span style=\"color:#ff0000; font-family:Calibri; font-size:12pt; font-weight:bold\">Evaluation Only. Created with Aspose.Words. Copyright 2003-2011 Aspose Pty Ltd.</span></p><h2 style=\"font-size:13pt; line-height:115%; margin:10pt 0pt 0pt; page-break-after:avoid; page-break-inside:avoid\"><span style=\"color:#4f81bd; font-family:Cambria; font-size:13pt; font-weight:bold\">This is a header</span></h2><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 10pt\"><span style=\"font-family:Calibri; font-size:11pt\"> </span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 10pt\"><span style=\"font-family:Calibri; font-size:11pt\">Look at my awesome bulleted list.</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 10pt\"><span style=\"font-family:Calibri; font-size:11pt\"> </span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 18pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">1)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Option 1</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">a)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Sup Option A</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">b)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Sub Option B</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">c)</span><span style=\"font:7.0pt 'Times New Roman'\">       </span><span style=\"font-family:Calibri; font-size:11pt\">Sub Option C</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 18pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">2)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Option 2</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">a)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Sub Option A</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 54pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">i)</span><span style=\"font:7.0pt 'Times New Roman'\">        </span><span style=\"font-family:Calibri; font-size:11pt\">Sub </span><span style=\"font-family:Calibri; font-size:11pt\">Sub</span><span style=\"font-family:Calibri; font-size:11pt\"> Option </span><span style=\"font-family:Calibri; font-size:11pt\">i</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 36pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">b)</span><span style=\"font:7.0pt 'Times New Roman'\">      </span><span style=\"font-family:Calibri; font-size:11pt\">Sub Option B</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 0pt 54pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">i)</span><span style=\"font:7.0pt 'Times New Roman'\">        </span><span style=\"font-family:Calibri; font-size:11pt\">Sub </span><span style=\"font-family:Calibri; font-size:11pt\">Sub</span><span style=\"font-family:Calibri; font-size:11pt\"> Option </span><span style=\"font-family:Calibri; font-size:11pt\">i</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 10pt 54pt; text-indent:-18pt\"><span style=\"font-family:Calibri; font-size:11pt\">ii)</span><span style=\"font:7.0pt 'Times New Roman'\">       </span><span style=\"font-family:Calibri; font-size:11pt\">Sub </span><span style=\"font-family:Calibri; font-size:11pt\">Sub</span><span style=\"font-family:Calibri; font-size:11pt\"> Option ii</span></p><p style=\"font-size:11pt; line-height:115%; margin:0pt 0pt 10pt\"><span style=\"font-family:Calibri; font-size:11pt\"> </span></p><p style=\"border-bottom-color:#4f81bd; border-bottom-style:solid; border-bottom-width:0.5pt; font-size:11pt; line-height:115%; margin:10pt 46.8pt 14pt; padding-bottom:4pt\"><span style=\"color:#4f81bd; font-family:Calibri; font-size:11pt; font-style:italic; font-weight:bold\">This is another heading</span></p></div></body></html>" string