Java Hex to Unicode ConvertHexToUnicode(String hexCode)

Here you can find the source of ConvertHexToUnicode(String hexCode)

Description

Method to convert Hex representation to Unicode using Linear Scan

License

Apache License

Parameter

Parameter Description
hexCode String Hex Code representation

Return

String Unicode text

Declaration

public static String ConvertHexToUnicode(String hexCode) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*www  . jav  a  2 s .  co m*/
     * Method to convert Hex representation to Unicode using Linear Scan
     * @param hexCode String Hex Code representation
     * @return String Unicode text
     */
    public static String ConvertHexToUnicode(String hexCode) {
        String toRet = "", nums = "";
        boolean flag = false;
        StringBuilder token = new StringBuilder();

        char[] ch = hexCode.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            if (ch[i] == '&') {
                flag = true;
            }

            /** Updating the Chain */
            if (flag) {
                token.append(ch[i]);
                if (ch[i] == ';') {
                    nums = token.toString().substring(2, token.toString().indexOf(";"));
                    try {
                        toRet += (char) Integer.parseInt(nums);
                    } catch (Exception e) {
                        toRet += token;
                    }
                    flag = false;
                    token.setLength(0);
                }
            } else {
                toRet += ch[i];
            }
        }

        return toRet.trim();
    }
}

Related

  1. convertHexToUni(String theNumber)