1

I have a string which is decoded by windows-1256 like this

A0C8E5CFC7CF2DC7DDDEE5ED

I want to encode that to UTF-8 in android. I tried to encode like this

String input = "A0C8E5CFC7CF2DC7DDDEE5ED";
    try {
        String message = new String(input.getBytes(), "windows-1256");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

but I didn't see what expected expression. I wrote some codes in C# for this purpose ,like this

int index = 0;
while (response[index] != 0x00)
    result = result + Encoding.GetEncoding("windows-1256").GetString(response, index++, 1);

it works fine.

does anyone have any idea how to solve it?

Thanks in advance

1 Answers1

1

First you convert your hex string into byte array. See this post.

Then, convert the byte array byte[] into UTF-8 using

String str = new String(byte[], "windows-1256");

UTF-8 is the native android encoding. Hope it helps.

Community
  • 1
  • 1
alsaleem
  • 347
  • 3
  • 16