Manoj Kumar
Manoj Kumar

Reputation: 317

How to convert unicode into string in android

I want to convert unicode string to string. I faced may method. But i did not get any useful answer for me. For example, If i send "b'day" string on server ,then i get "b’day" string from server . How to check comming string from server is string or unicode string. If you know, Please help me .

Thanks in advance

Upvotes: 1

Views: 3061

Answers (1)

CodeWarrior
CodeWarrior

Reputation: 5176

For that you'll have to :

  1. Parse the text into the separate unicode digits.
  2. Then do Integer.ParseInt(XXXX, 16) to get a hex value.
  3. Then switch case that to char to get the actual character.

    String str = myString.split(" ")[0];
    str = str.replace("\\","");
    String[] array = str.split("u");
    String stringText = "";
    for(int i = 1; i < array.length; i++){
        int hexValue = Integer.parseInt(array[i], 16);
        stringText += (char)hexValue;
    }
    textView.setText(Html.fromHtml(stringText));
    

&#8217; is the Html representation for ( ' ) in Unicode.

You can get your desired output by Html.fromHtml(stringText)

Upvotes: 1

Related Questions