简体   繁体   中英

C# Display Special Characters in TextBlock

In my Windows Phone application, I take RSS from Internet and I parse XML. I take out Title and Description from rss, and display them in a TextBlock.

Here I find some problems, the speacial characters are substituted by rhombus contain "?".

  /*CONNECTION AND DOWNLOAD RSS*/ WebClient wc = new WebClient(); wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(load_web_news); wc.DownloadStringAsync(new Uri("http://.../rssFeedNews.asp")); .... /*SAVE RSS*/ TextBlock tbTitle = new TextBlock(); Run rTitle = new Run(); rTitle.Text = rss.Title; Run rDescription = new Run(); rDescription.Text = rss.Description; tbTitle.Inlines.Add(rTitle); .... /*PARSING*/ private void load_web_news(object sender, DownloadStringCompletedEventArgs e) { XElement xmlitems = XElement.Parse(e.Result); List<XElement> elements = xmlitems.Descendants("item").ToList(); foreach (XElement rssItem in elements) { RSSItem rss = new RSSItem(); rss.Description1 = rssItem.Element("description").Value; String title = rssItem.Element("title").Value; 

How to display special chars for example "à" "è" "°" etc... in a WIndows phone app?

The WebClient is probably not using the right encoding to dowload your rss feed, try setting the Encoding property to the right one (maybe Unicode?):

wc.Encoding = System.Text.Encoding.Unicode;

or if you know which specific encoding is used :

wc.Encoding = System.Text.Encoding.GetEncoding("encoding name here") ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM