Java Array to String arrayToString(final byte[] array, final int start, final int length)

Here you can find the source of arrayToString(final byte[] array, final int start, final int length)

Description

Convert the contents of the specified array to a String, starting at an offset of start, for length.

License

Open Source License

Parameter

Parameter Description
array a parameter
start a parameter
length a parameter

Return

String

Declaration


public static String arrayToString(final byte[] array, final int start, final int length) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

public class Main {
    /***********************************************************************************************
     * Convert the contents of the specified array to a <code><b>String</b></code>,
     * starting at an offset of <code>start</code>, for <code>length</code>.
     *//  w  w w.jav a 2s .co  m
     * @param array
     * @param start
     * @param length
     *
     * @return String
     */

    public static String arrayToString(final byte[] array, final int start, final int length) {
        int i;
        int count;
        final byte[] temp;

        count = 0;
        temp = new byte[length];

        for (i = start; i < (start + length); i++) {
            if ((array[i] >= 0) && (array[i] < 32)) {
                // Control characters are replaced by spaces
                temp[count] = 32;
            } else {
                temp[count] = array[i];
            }

            count++;
        }

        return (new String(temp));
    }
}

Related

  1. arrayToString(double[] array)
  2. arrayToString(double[] array, String separator)
  3. arrayToString(double[] v)
  4. arrayToString(double[] xs)
  5. arrayToString(final byte[] array)
  6. arrayToString(final float[] array)
  7. arrayToString(final Object[] a)
  8. arrayToString(final Object[] arr)
  9. arrayToString(final Object[] array)