Java Hex Convert To convertHexChars(final String value)

Here you can find the source of convertHexChars(final String value)

Description

turn any hex values (ie #e4) into chars

License

Open Source License

Parameter

Parameter Description
value a parameter

Declaration

public static final String convertHexChars(final String value) 

Method Source Code

//package com.java2s;
/*//  w w w.  ja  v a 2s  .c o m
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2016 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
 This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
    
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
    
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    
    
 *
 * ---------------
 * StringUtils.java
 * ---------------
 */

public class Main {
    private static final int hashInt = 35;
    private static final int spaceInt = 32;

    /**
     * turn any hex values (ie #e4) into chars
     * @param value
     * @return
     */
    public static final String convertHexChars(final String value) {

        //avoid null
        if (value == null) {
            return value;
        }

        //find char
        final int escapeChar = value.indexOf(hashInt);

        if (escapeChar == -1) {
            return value;
        }

        //process
        final StringBuilder newString = new StringBuilder();
        final int length = value.length();
        //newString.setLength(length);

        char c;

        for (int ii = 0; ii < length; ii++) {
            c = value.charAt(ii);

            if (c == hashInt) {
                ii++;
                int end = ii + 2;
                if (end > length) {
                    end = length;
                }
                final String key = value.substring(ii, end);

                c = (char) Integer.parseInt(key, 16);

                ii++;

                if (c != spaceInt) {
                    newString.append(c);
                }
            } else {
                newString.append(c);
            }

        }

        return newString.toString();
    }
}

Related

  1. convertHex(char c)
  2. convertHexa(String bool)
  3. convertHexadecimal2RGB(final String hexColor, final String divider)
  4. convertHexByteToTelcoChar(byte byteValue)
  5. convertHexColorToRgb(final String hex)
  6. convertHexFloatingPointLiteralToBits(char[] source)
  7. convertHexLong(String hex)
  8. convertHexStringToBinary(String hexString)