c# - How can I encode string in file content? -


this did before in form1 constructor:

client.encoding = system.text.encoding.getencoding(1255); page = client.downloadstring("http://rotter.net/scoopscache.html"); 

client = webclient variable page = string variable

but changed , i'm doing in form1 constructor:

page = offlinedownload.offlinehtmlfile1(); 

now page have same content before without downloading it. how can encoding 1255 since of content in page in hebrew?

i tried this:

page = encoding.getencoding(1255).tostring(); page = offlinedownload.offlinehtmlfile1(); 

but it's not working got error later since content not in hebrew yet symbols , chars more gibrish.

the offline class:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.net; using system.io;  namespace scrolllabeltest {     class offlinedownload     {         static string offlinehtmlbeforechanged;         static string offlinehtmlafterchanged;          public static string offlinehtmlfile1()         {             offlinehtmlbeforechanged = file.readalltext(@"c:\temp\news\news1.htm");             return offlinehtmlbeforechanged;         }          public static string offlinehtmlfile2()         {             offlinehtmlafterchanged = file.readalltext(@"c:\temp\news\news2.htm");             return offlinehtmlafterchanged;         }     } } 

from system.net.webclient.downloadstring

byte[] bytes = this.downloaddatainternal(address, out request); string @string = this.guessdownloadencoding(request).getstring(bytes); 

which equivalent to

byte[] bytes = file.readallbytes(filename); string @string = encoding.getencoding(1255).getstring(bytes); 

although hans points out, it's better in 1 go

string @string = file.readalltext(filename, encoding.getencoding(1255)); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -