Why can not decode persian character from csv file with c#? -
i'm write code read csv file:
var reader = new streamreader(file.openread(@"c:\test.csv")); list<string> lista = new list<string>(); list<string> listb = new list<string>(); while (!reader.endofstream) { var line = reader.readline(); var values = line.split(';'); lista.add(values[0]); listb.add(values[1]); }
, sample csv file recode here:
استان نمونه عمليات دوره صورت حساب- دوره اول سال 1393 1393,01,01 1393,03,01`enter code here`
when debug program,i data sample line:
��� ���� �������,��� ������
happen?why can see data csv file? when open file visual studio see this:
if has done once, easiest way open csv file , convert unicode text. open csv file in visual studio , following:
choose file -> advanced save options -> choose 'unicode (utf-8 signature) - codepage 65001' -> save file , try again
.
according msdn, stream reader should able pick correct encoding.
the streamreader object attempts detect encoding looking @ first 3 bytes of stream. automatically recognizes utf-8, little-endian unicode, , big-endian unicode text if file starts appropriate byte order marks.
edit:
change code to:
var reader = new streamreader(file.openread(@"c:\test.csv"), encoding.getencoding(1256));
Comments
Post a Comment