Java tutorial
//package com.java2s; /* Copyright 2008 San Jose State University This file is part of the Blackberry Cinequest client. The Blackberry Cinequest client is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The Blackberry Cinequest client is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the Blackberry Cinequest client. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Trims leading and trailing spaces from a string buffer * @param buffer the buffer to be edited */ public static void trim(StringBuffer buffer) { int i = 0; while (i < buffer.length() && isSpace(buffer.charAt(i))) i++; buffer.delete(0, i); int j = buffer.length() - 1; while (j >= 0 && isSpace(buffer.charAt(j))) j--; buffer.setLength(j + 1); } private static boolean isSpace(char ch) { return ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r'; } }