0

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? enter image description here

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.