Java Unicode Create getUnicodeString(byte[] d, int length, int pos)

Here you can find the source of getUnicodeString(byte[] d, int length, int pos)

Description

Gets a string from the data array

License

Open Source License

Parameter

Parameter Description
pos The start position of the string
length The number of characters to be converted into a string
d The byte data

Return

the string built up from the unicode characters

Declaration

public static String getUnicodeString(byte[] d, int length, int pos) 

Method Source Code


//package com.java2s;
/*/*from www  .j  a v a 2s  .  c  om*/
 * Copyright (c) 2007-2016 AREasy Runtime
 *
 * This library, AREasy Runtime and API for BMC Remedy AR System, is free software ("Licensed 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;
 * including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT,
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 */

import java.io.UnsupportedEncodingException;

public class Main {
    public static String UNICODE_ENCODING = "UnicodeLittle";

    /**
     * Gets a string from the data array
     *
     * @param pos   The start position of the string
     * @param length The number of characters to be converted into a string
     * @param d     The byte data
     * @return the string built up from the unicode characters
     */
    public static String getUnicodeString(byte[] d, int length, int pos) {
        try {
            byte[] b = new byte[length * 2];
            System.arraycopy(d, pos, b, 0, length * 2);
            return new String(b, UNICODE_ENCODING);
        } catch (UnsupportedEncodingException e) {
            // Fail silently
            return "";
        }
    }
}

Related

  1. getUnicodeByteArray(String str)
  2. getUnicodeBytes(String s)
  3. getUnicodeString(byte bytes[], int offset, int len)
  4. getUnicodeText(Object text)
  5. toUnicode(char c)
  6. toUnicode(final String toUnicode, final boolean toLowerCase)
  7. toUnicode(String input)