Link to home
Start Free TrialLog in
Avatar of smantha1979
smantha1979

asked on

how to read unicode datas from mysql and save it to xml file?

i can view the datas with php throught web pages. but when i try to read the data with C# and save to xml, it doesn't work :(
Avatar of tzxie2000
tzxie2000
Flag of China image

suggest the data you read from mysql is store in char[] sa and it is a UniCode

char [] sa;
string s

//some code to receive data in s or sa
//you can change s to sa by your demand

Encoder UniCodeEncoder = Encoding.UniCode.GetEncoder();

int byteCount = UniCodeEncoder.GetByteCount(s, 0, s.Length, true);
Byte[] bytes = new Byte[byteCount];
int bytesEncodedCount = UniCodeEncoder.GetBytes(s, 0,s.Length, bytes, 0, true);
//ok it change to UniCode
// bytesEncodedCount is the real changed bytes number
 Console.WriteLine("{0} bytes used to encode characters.", bytesEncodedCount );
//show the encoded bytes
Console.Write("Encoded bytes: ");
  foreach (Byte b in s) {
        Console.Write("[{0}]", b);
   }//the result is save in bytes

Avatar of smantha1979
smantha1979

ASKER

thankz for reply.
i found out that, its because of bytefx, bytefx depends on mysql's server character, and mysql uses latin, that's why it can't read when the character set doesn't match the default character set,, i give myself 250 points :)
ASKER CERTIFIED SOLUTION
Avatar of CetusMOD
CetusMOD
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial