将HTML字符串转换为文本文件 [英] Convert HTML String to text file

查看:170
本文介绍了将HTML字符串转换为文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的字符串



Hi,
This is My string

string st = "<div align="center" style=" width: 45.3mm;font-size: 8pt;font-family: calibri;background: white;"><div class="subpage">Welcome Naveen Store #5300/3 M.H.C Manimajra 160101 Chandigarh Punjab 160101 Ph: 9463946352 Fax: 1231231231 <table style=" width: 45.3mm;font-size: 8pt;font-family: calibri;background: white;"><tr><td>CARD#:</td><td>fgy65</td></tr> <tr><td>BALANCE:</td><td>$55</td></tr><tr><td>PAYMENT TYPE: </td><td>AMERICAN EXPRESS</td></tr><tr><td align="center" colspan="2">      7/18/2014 9:48:02 PM</td></tr></table>Thanks for Comes to my store.</div></div";







StreamWriter objReader = null;
       try
       {
           //objReader = new StreamWriter(@"D:\test.html");
           objReader = new StreamWriter(@"F:\Richa222.txt");
           objReader.Write(st);
       }
       finally
       {
           objReader.Close();
       }





现在我想将此字符串转换为包含所有对齐样式和字体及字体系列的文本文件..请帮助我如何做到这一点。



谢谢

推荐答案

55 < / td > < / tr > < tr > < span class =code-keyword>< td > 付款方式:< span class =code-keyword>< / td > < td > AMERICAN EXPRESS < / td > < / tr > < span class =code-keyword>< tr > < td align = center colspan = 2 < span class =code-keyword>> 7/18/2014 9:48:02 PM < / td > < / tr > < / table > 感谢您光临我的商店。< / div > < / div;
55</td></tr><tr><td>PAYMENT TYPE: </td><td>AMERICAN EXPRESS</td></tr><tr><td align="center" colspan="2">      7/18/2014 9:48:02 PM</td></tr></table>Thanks for Comes to my store.</div></div";







StreamWriter objReader = null;
       try
       {
           //objReader = new StreamWriter(@"D:\test.html");
           objReader = new StreamWriter(@"F:\Richa222.txt");
           objReader.Write(st);
       }
       finally
       {
           objReader.Close();
       }





现在我想将此字符串转换为包含所有对齐样式和字体及字体系列的文本文件..请帮帮我怎样才能做到这一点。



谢谢


你甚至不能手动完成。



.txt文件在这种情况下是不够的。



你应该尝试写一个.doc file。
You can't even do it manually.

.txt files are not adequate in this case.

You should try to write a .doc file.


您不能在txt文件中应用HTML格式。但是如果你只想在那里保存html,你可以......



来自这里 [ ^ ]。

You cannot apply HTML format in a txt file. But if you only want to save the html there you can...

Just from here[^].
StreamWriter objReader = null;
try
{
    string encoded = HttpContext.Current.Server.HtmlEncode(st);
    objReader = new StreamWriter(@"F:\Richa222.txt");
    objReader.Write(encoded);
}
catch
{
    //catch error here
}
finally
{
    objReader.Close();
}



希望有所帮助。


Hope it helps.


这篇关于将HTML字符串转换为文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆