正确编码字符串

时间:2016-06-01 07:22:51

标签: c# encoding

我需要正确编码字符串:

string Nazev="TriŔko Chevak";

我需要这个:

string Nazev="Tričko Chevak";

我试试这个,但没有变化:

Encoding win = Encoding.GetEncoding(1250);
Encoding z = Encoding.Default;
byte[] zBytes = z.GetBytes(Nazev);
byte[] isoBytes = Encoding.Convert(z, win, zBytes);
Nazev = win.GetString(isoBytes);

你有什么想法吗?

我打开* .DBF文件并将值加载到datatable:

string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(NovyNazevCSV) + ";Extended Properties=\"dBASE IV;Text;CharacterSet=1250;\"";
            using (OleDbConnection con = new OleDbConnection(constr))
            {
                var sql = "select * from " + Path.GetFileName(NovyNazevCSV);
                OleDbCommand cmd = new OleDbCommand(sql, con);
                con.Open();
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                da.Fill(dtBush);
            }
foreach (DataRow radekBush in dtBush.Rows) 
{
Nazev = radekBush[3].ToString();
}

在文件中我有: Tričko但在数据表中我有TriŔko......

1 个答案:

答案 0 :(得分:0)

Encoding.Default将返回默认的ANSI编码,请尝试使用UTF-8编码:

...
Encoding z = Encoding.UTF8;
...

您也可以尝试在连接字符串中使用CharacterSet=65001