Java Char Convert To convertCharacterEntity(String value)

Here you can find the source of convertCharacterEntity(String value)

Description

convert Character Entity

License

Mozilla Public License

Declaration

public static char convertCharacterEntity(String value) 

Method Source Code

//package com.java2s;
/*//from  ww w.j  a  v a  2s  .co m
 * $Id: CommonEntities.java,v 1.1 2004/03/25 18:41:32 edankert Exp $
 *
 * The contents of this file are subject to the Mozilla Public License 
 * Version 1.1 (the "License"); you may not use this file except in 
 * compliance with the License. You may obtain a copy of the License at 
 * http://www.mozilla.org/MPL/ 
 *
 * Software distributed under the License is distributed on an "AS IS" basis, 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
 * for the specific language governing rights and limitations under the License.
 *
 * The Original Code is eXchaNGeR browser code. (org.xngr.browser.*)
 *
 * The Initial Developer of the Original Code is Cladonia Ltd.. Portions created 
 * by the Initial Developer are Copyright (C) 2002 the Initial Developer. 
 * All Rights Reserved. 
 *
 * Contributor(s): Dogsbay
 */

public class Main {
    public static char convertCharacterEntity(String value) {
        return convert(value);
    }

    private static char convert(String value) {
        char result = (char) -1;

        if (value != null && value.length() > 3) {
            String code = value.substring(2, value.length() - 1);

            if (code.startsWith("x") || code.startsWith("X")) {
                try {
                    Integer val = Integer.decode("0" + code);
                    result = (char) val.intValue();
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    result = (char) Integer.parseInt(code);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        }

        return result;
    }
}

Related

  1. charToNybble(char c)
  2. charToOctet(char c)
  3. charToUpperOrLower(String string, int pos, boolean upper)
  4. convertChar(char c)
  5. convertCharacter(final String value)
  6. convertCharacterOffsetToCodePointOffset(String inputStr, int charOffset)
  7. convertCharacters(String fileName)
  8. convertCharArray(char[] arr)
  9. convertCharArrayToIntArray(char[] chars)