简体   繁体   中英

Unicode string from Windows .NET to Android Java

Please, give me the correct transformation set of functions to in Java to receive correct result.

Windows.NET part.

Some UNICODE string data is converted to byte array using

Encoding.Unicode.ToBytes(SomeString);

Android Java

byte[] buffer is transferred to Android Java as it is. Using new String(byte[], "utf-16") doesn't give the correct string. Someone said it is because of Big or Little ending order of one char byte. I'am not sure if Unicode.Net and utf-16 are the same. Is it the same?

Is there a standard library that is responsible for such transformation or every programmer should develop own function to convert from big to little endians and so on?

the study has shown that extra -1 -2 are added under Java.. What these two bytes means? 在此处输入图片说明

The extra first two bytes [-1, -2] are Byte Order Mark (BOM) . You can read more about it on Wiki Page .

You should add BOM at the beginning of your byte[]. I used the following code snippet in C# to convert String to byte[] including BOM.

var result = Encoding.Unicode.GetPreamble().Concat(Encoding.Unicode.GetBytes("Sample Unicode Text")).ToArray();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM