Im trying to read rss feed from a website but the hebrew fonts i see it like gibrish how can i fix it?

StackOverflow https://stackoverflow.com/questions/21370199

This is in hebrew language the website. But the fonts are like gibrish.

In form1 i have:

readableRss = RssReader.covertRss("http://rotter.net/rss/rotternews.xml");
textBox1.Text = readableRss;

Then in the class RssReader i have:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Data;
using System.Xml.Linq;

namespace RssNews
{
    class RssReader
    {
        public class RssNews
        {
            public string Title;
            public string PublicationDate;
            public string Description;
        }

        public class RssReading
        {
            public static List<RssNews> Read(string url)
            {
                var webClient = new WebClient();

                string result = webClient.DownloadString(url);

                XDocument document = XDocument.Parse(result);

                return (from descendant in document.Descendants("item")
                        select new RssNews()
                        {
                            Description = descendant.Element("description").Value,
                            Title = descendant.Element("title").Value,
                            PublicationDate = descendant.Element("pubDate").Value
                        }).ToList();
            }
        }


        public static string covertRss(string url)
        {
            var s = RssReading.Read(url);
            StringBuilder sb = new StringBuilder();
            foreach (RssNews rs in s)
            {
                sb.AppendLine(rs.Title);
                sb.AppendLine(rs.PublicationDate);
                sb.AppendLine(rs.Description);
            }

            return sb.ToString();
        }
    }
}

And this is what i see in textBox1:

ðúðéäå ÷éååä ìùîåò ''ìà'' îàáå îàæï - åàæ áðè ÷ôõ
Sun, 26 Jan 2014 23:52:55 +0200

ôéöåõ àãéø ðùîò áëì øçáé ìè÷éä.îáæ÷éí îäî÷åí.
Sun, 26 Jan 2014 23:37:13 +0200

îùøã äçéðåê éëôéì àú ú÷öåá îôâùé ääéãáøåú áéï éäåãéí åòøáéí
Sun, 26 Jan 2014 23:37:05 +0200

ãå''ç ôðèâåï: ''àøä''á àéðä îñåâìú  ìò÷åá àçø áðééú ðù÷ âøòéðé áîãéðåú òåéðåú
Sun, 26 Jan 2014 23:30:42 +0200

ãéååç ìáðåðé òì èéñåú ëáãåú áá÷òú äìáðåï
Sun, 26 Jan 2014 23:24:20 +0200

I tried this but it didnt help:

Encoding hebrewEncoding = Encoding.GetEncoding(862);
            readableRss = RssReader.covertRss("http://rotter.net/rss/rotternews.xml");
            byte[] hebBytes = hebrewEncoding.GetBytes(readableRss);
            string h = hebrewEncoding.GetString(hebBytes);
            textBox1.Text = h;

How can i change this fonts so i will see the hebrew ?

有帮助吗?

解决方案

The encoder should be set for the webClient in the RssReading.Read() method

 webClient.Encoding = Encoding.GetEncoding("windows-1255");
 string result = webClient.DownloadString(url);

Sorry I don't have a font with correct ligatures, but I believe this will works:

hebrew text shown

So you can keep

readableRss = RssReader.covertRss("http://rotter.net/rss/rotternews.xml");
textBox1.Text = readableRss;

其他提示

There is another option, the

"windows-1255"

didn't work for me

WebClient wc = new WebClient();
//Reading Hebrew Characters
wc.Encoding = Encoding.UTF8;
string rssData = wc.DownloadString(rssUrl);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top