Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

UTF-8: WriteAllText and StrinBuilder

$
0
0

Hello, utf-8 characters problem in Result.txt

using System;
using System.Linq;
using System.Text;
using HtmlAgilityPack;

namespace DemoHtmlAgilityPack
{
    class Program
    {
        static StringBuilder text = new StringBuilder();

        private static void Main(string[] args)
        {

            var client = new System.Net.WebClient();

            client.Encoding = Encoding.UTF8;

            var filename = System.IO.Path.GetTempFileName();

            string s = client.DownloadString("http://fastandclever.ru");
            System.IO.File.WriteAllText(@"C:\TEST\page.html", s);

            HtmlDocument doc = new HtmlDocument();
            doc.Load(@"C:\TEST\page.html");

            var root = doc.DocumentNode;

            var a_nodes = root.Descendants("a").ToList();

            Console.WriteLine(s);
            Console.ReadKey();

            foreach (var a_node in a_nodes)
            {
                text.Append("LINK: " + a_node.GetAttributeValue("href", "") + "\nTEXT: " + a_node.InnerText + "\n\n");
            }

            System.IO.File.WriteAllText(@"C:\TEST\Result.txt", text.ToString(), Encoding.UTF8);

        }
    }
}

I try to get utf-8 characters encoding, but without luck. In cmd russian characters show properly, but not in Result.txt.

Thanks!



Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>