如何使用所有Unicode将单词转换为HTML. [英] how to convert word to HTML with all Unicodes.

查看:130
本文介绍了如何使用所有Unicode将单词转换为HTML.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用所有Unicode将单词转换为HTML.意味着转换后如果我在word文档中有空格",则应显示为& nbsp;

how to convert word to HTML with all unicodes. Means if i have ''space'' in word document after conversion should be shown me as  

推荐答案

Hey Prasad,

您可以使用HtmlEncode,然后使用扩展方法替换空白字符.

HtmlEncode仅用于编码字符以在HTML中显示.它专门不对空格字符进行编码.您可以使用String.Replace()编码换行符和空格(如果需要更好的匹配,也可以使用Regex.Replace编码).
http://stackoverflow.com/questions/524528/asp-net-mvc- html-encode-new-lines [ ^ ]

希望对您有所帮助.
Hey Prasad,

You can use HtmlEncode and then replace the white space characters using extension method.

HtmlEncode is only meant to encode characters for display in HTML. It specifically does not encode whitespace characters. You could use String.Replace() to encode the newlines and spaces (or Regex.Replace if you need better matching).
http://stackoverflow.com/questions/524528/asp-net-mvc-html-encode-new-lines[^]

I hope this helps.


您应该将所有空格字符转换为不间断空格.这将导致每段大而牢不可破的一行!另外,您的问题与Unicode无关.

如果Word的默认默认值另存为HTML"不足以满足您的要求,则应编写一些宏,这些宏将每个段落和行内格式化的块包装在一起,并带有HTML标记以反映您想要的内容,例如标题2-> < h2> ;,普通-> < p> ;,代码块-> < pre>.您还应该使用HtmlEncode对在HTML中具有特殊含义的字符进行编码-但空格不是其中之一.

请记住,并非Word文档中的所有内容都可以用HTML精确地表示,并且文档和网页的约定也有所不同.不要期望确切的转换.
You should not convert all white space characters to non-breaking spaces. That will result in one huge, unbreakable line per paragraph! Also, your question has nothing to do with Unicode.

If Word''s default ''Save as HTML'' is not sufficient for your requirements, you should write some macros which wrap each paragraph, and in-line formatted blocks, with HTML tags to reflect what you want – e.g. Heading 2 -> <h2>, Normal -> <p>, Code block -> <pre>. You should also use HtmlEncode to encode characters which have special meaning in HTML – but spaces are not one of those.

Remember that not everything in a Word document is representable exactly in HTML, and the conventions for documents and web pages are different. Don''t expect an exact conversion.


这篇关于如何使用所有Unicode将单词转换为HTML.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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