A
Alci
I am getting some Korean characters data from MS SQL server. These
data were submitted as UTF-8 into the database, but stored as normal
varchars. So, when I getting them out of database by using Gridview
+SqlDataSource, they are actually ASCII format, but I couldn't just
convert the encoding of the page to get the proper UTF-8 format Korean
texts.
So, i modified a function from MS site, try to convert ASCII to UTF-8,
as below
protected string Convertor(string asciiString)
{
System.Text.Encoding ascii = System.Text.Encoding.ASCII;
System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
byte[] asciiBytes = ascii.GetBytes(asciiString);
byte[] utf8Bytes = System.Text.Encoding.Convert(ascii, utf8,
asciiBytes);
char[] utf8Chars = new char[utf8.GetCharCount(utf8Bytes, 0,
utf8Bytes.Length)];
utf8.GetChars(utf8Bytes, 0, utf8Bytes.Length, utf8Chars, 0);
string utf8String = new string(utf8Chars);
return utf8String;
}
But this doesn't work, all i get are question marks ???.
Anyone knows how do i solve this problem? From the SQL server side or
in the ASP.NET code?
data were submitted as UTF-8 into the database, but stored as normal
varchars. So, when I getting them out of database by using Gridview
+SqlDataSource, they are actually ASCII format, but I couldn't just
convert the encoding of the page to get the proper UTF-8 format Korean
texts.
So, i modified a function from MS site, try to convert ASCII to UTF-8,
as below
protected string Convertor(string asciiString)
{
System.Text.Encoding ascii = System.Text.Encoding.ASCII;
System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
byte[] asciiBytes = ascii.GetBytes(asciiString);
byte[] utf8Bytes = System.Text.Encoding.Convert(ascii, utf8,
asciiBytes);
char[] utf8Chars = new char[utf8.GetCharCount(utf8Bytes, 0,
utf8Bytes.Length)];
utf8.GetChars(utf8Bytes, 0, utf8Bytes.Length, utf8Chars, 0);
string utf8String = new string(utf8Chars);
return utf8String;
}
But this doesn't work, all i get are question marks ???.
Anyone knows how do i solve this problem? From the SQL server side or
in the ASP.NET code?