Java UTF from toUtf8(String hex)

Here you can find the source of toUtf8(String hex)

Description

Method converts hex string into utf8 string

License

Open Source License

Parameter

Parameter Description
hex a parameter

Return

String

Declaration

public static String toUtf8(String hex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final String HEX_PREFIX = "0x";

    /**//from w w w  .j  a  v a 2  s  . c o m
     * Method converts hex string into utf8 string
     *
     * @param hex
     * @return String
     */
    public static String toUtf8(String hex) {
        String result = "";
        int i = 0, length = hex.length();
        if (hex.substring(0, 2).equals(HEX_PREFIX)) {
            i = 2;
        }
        for (; i < length; i += 2) {
            int code = Integer.parseInt(hex.substring(i, i + 2), 16);
            result += Character.toString((char) code);
        }
        return result;
    }
}

Related

  1. ToUTF(String s)
  2. toUTF(String str)
  3. toUTF(String... str)
  4. toUTF8(byte[] outputBuffer, String string, char[] workingBuffer)
  5. toUtf8(final String string)
  6. toUTF8(String oldStr)
  7. toUtf8(String s)
  8. toUTF8(String s)
  9. toUTF8(String s, String encoding)