I am receiving from some dll (which is wrapper for some external data source) strings in Windows-1250 codepage and I would like to insert them correctly (as unicode) to table in SQL Server Database. Since particular row in database which should hold that data is of NVarchar type, I only needed to convert it in my C# code to unicode and pass it as parameter. Everything is well and nice, but I stumbled on conversion step.
I tried the following but that doesn't work:
private static String getUnicodeValue(string string2Encode) //
{
Encoding srcEncoding = Encoding.GetEncoding("Windows-1250");
UnicodeEncoding dstEncoding = new UnicodeEncoding();
byte[] srcBytes = srcEncoding.GetBytes(string2Encode);
byte[] dstBytes = dstEncoding.GetBytes(string2Encode);
return dstEncoding.GetString(dstBytes);
}
When I insert this returned string to table, I don't get correct letters like Đ, đ, Č, č, Ć or ć.
Please, help! :)
the problem is string string2Encode
is in unicode already. (UTF-16 is internal encoding in .net) So if you want string in windows-1250, you have to pass byte[]
then do Encoding.GetEncoding("windows-1250").GetString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With