Return last position of space in byte array - Java java.lang

Java examples for java.lang:byte Array

Description

Return last position of space in byte array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte[] btBuff = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        int iOffset = 2;
        System.out.println(lastIndexOfSequenceSpace(btBuff, iOffset));
    }/*from w  w w  .  j a  v a  2  s  .c  o m*/

    /**
     * Return last position of space in byte array
     * @param btBuff buffer to search
     * @param iOffset start offset
     * @return first position of symbol in buffer, -1 if not found
     * @author Thai Hoang Hiep
     */
    ////////////////////////////////////////////////////////
    public static int lastIndexOfSequenceSpace(byte[] btBuff, int iOffset) {
        while (iOffset < btBuff.length && btBuff[iOffset] <= 32)
            iOffset++;
        if (iOffset >= btBuff.length)
            return -1;
        return iOffset;
    }
}

Related Tutorials