Java examples for java.nio:CharBuffer
Trim spaces in CharBuffer and tabs moving left from right
//package com.java2s; import java.nio.CharBuffer; public class Main { /**//from ww w.j a v a2s . c o m * Trim spaces and tabs moving left from toExc. Do not go beyond from. * * @return the position after removing whitespace, toExc if no whitespace was found */ public static int trimRight(CharBuffer buf, int from, int toExc) { for (int i = toExc - 1; i >= from; i--) { char c = buf.get(i); if (c != ' ' && c != '\t') { return i + 1; } } return toExc; } }