By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

Converting ASCII to UTF-8

P: n/a
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?
Nov 28 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.