久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將字符實體轉換為其 Unicode 等效項

Convert character entities to their unicode equivalents(將字符實體轉換為其 Unicode 等效項)
本文介紹了將字符實體轉換為其 Unicode 等效項的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在數據庫中有 html 編碼的字符串,但許多字符實體不僅僅是標準的 &<.“— 等實體.不幸的是,我們需要將這些數據提供給基于 flash 的 rss 閱讀器,而 flash 不會讀取這些實體,但它們會讀取等效的 unicode(例如 “).

I have html encoded strings in a database, but many of the character entities are not just the standard & and <. Entities like “ and —. Unfortunately we need to feed this data into a flash based rss reader and flash doesn't read these entities, but they do read the unicode equivalent (ex “).

使用 .Net 4.0,是否有任何實用方法可以將 html 編碼的字符串轉換為使用 unicode 編碼的字符實體?

Using .Net 4.0, is there any utility method that will convert the html encoded string to use unicode encoded character entities?

這是我需要的一個更好的例子.該數據庫具有 html 字符串,例如:

John &amp;莎拉去看 $ldquo;Scream 4$rdquo;.</p> 而我需要在 rss/xml 文檔中用 標簽輸出的是: &lt;p&gt;John &amp;#38;莎拉去看了&amp;#8220;Scream 4&amp;#8221;.&lt;/p&gt;

Here is a better example of what I need. The db has html strings like: <p>John &amp; Sarah went to see $ldquo;Scream 4$rdquo;.</p> and what I need to output in the rss/xml document with in the <description> tag is: &lt;p&gt;John &amp;#38; Sarah went to see &amp;#8220;Scream 4&amp;#8221;.&lt;/p&gt;

我正在使用 XmlTextWriter 從類似于此示例代碼的數據庫記錄創建 xml 文檔 http://www.dotnettutorials.com/tutorials/advanced/rss-feed-asp-net-csharp.aspx

I'm using an XmlTextWriter to create the xml document from the database records similar to this example code http://www.dotnettutorials.com/tutorials/advanced/rss-feed-asp-net-csharp.aspx

所以我需要用他們的 unicode equivilant 替換來自 db 的 html 字符串中的所有字符實體,因為基于 flash 的 rss 閱讀器無法識別任何實體,而不是最常見的實體,例如 &amp;.

So I need to replace all of the character entities within the html string from the db with their unicode equivilant because the flash based rss reader doesn't recognize any entities beyond the most common like &amp;.

推薦答案

我的第一個想法是,你的 RSS 閱讀器能接受實際的字符嗎?如果是這樣,您可以使用 HtmlDecode 和提要直接進去.

My first thought is, can your RSS reader accept the actual characters? If so, you can use HtmlDecode and feed it directly in.

如果確實需要將其轉換為數字表示,則可以解析出每個實體,HtmlDecode,然后將其轉換為 int 以獲得基數-10 Unicode 值.然后重新插入到字符串中.

If you do need to convert it to the numeric representations, you could parse out each entity, HtmlDecode it, and then cast it to an int to get the base-10 unicode value. Then re-insert it into the string.

下面是一些代碼來演示我的意思(未經測試,但可以理解):

Here's some code to demonstrate what I mean (it is untested, but gets the idea across):

string input = "Something with &mdash; or other character entities.";
StringBuilder output = new StringBuilder(input.Length);

for (int i = 0; i < input.Length; i++)
{
    if (input[i] == '&')
    {
        int startOfEntity = i; // just for easier reading
        int endOfEntity = input.IndexOf(';', startOfEntity);
        string entity = input.Substring(startOfEntity, endOfEntity - startOfEntity);
        int unicodeNumber = (int)(HttpUtility.HtmlDecode(entity)[0]);
        output.Append("&#" + unicodeNumber + ";");
        i = endOfEntity; // continue parsing after the end of the entity
    }
    else
        output.Append(input[i]);
}

我可能在某個地方有一個逐一錯誤,但應該很接近.

I may have an off-by-one error somewhere in there, but it should be close.

這篇關于將字符實體轉換為其 Unicode 等效項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is there a way to know if someone has bookmarked your website?(有沒有辦法知道是否有人為您的網站添加了書簽?)
Use of Different .Net Languages?(使用不同的 .Net 語言?)
Is there a C# library that will perform the Excel NORMINV function?(是否有執行 Excel NORMINV 函數的 C# 庫?)
Determining an #39;active#39; user count of an ASP.NET site(確定 ASP.NET 站點的“活動用戶數)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權列表中選擇 x 個隨機元素(無需替換))
Best way to keep track of current online users(跟蹤當前在線用戶的最佳方式)
主站蜘蛛池模板: 成人久久久 | 综合久久久久 | 国产精品久久久久久久7777 | 一区二区三区视频免费观看 | 国产一二区免费视频 | 三级欧美 | 亚洲色图网址 | 一级黄色片免费 | 久久久久亚洲 | 亚洲视频在线观看 | 亚洲顶级毛片 | 久久成人在线视频 | 国产精品视频播放 | 久久在视频 | 91www在线观看 | 久久国产高清 | 久色网| 精品久久国产 | 久久久.com| 午夜三级网站 | 欧美激情欧美激情在线五月 | 先锋资源网| 韩日视频在线观看 | 午夜精品一区二区三区免费视频 | 天天天天操 | 久久毛片 | 久久久精品一区 | 国际精品鲁一鲁一区二区小说 | 麻豆久久精品 | 黑人巨大精品欧美一区二区一视频 | 一区亚洲 | 日本免费黄色一级片 | 国产资源在线播放 | 亚洲国产精品一区二区第一页 | 亚洲欧美日韩成人在线 | 国产精品观看 | 国产特黄一级 | xxxxxx国产 | 成av在线| 夜夜夜操 | 免费久久久久久 |