Java String Chop chop(String aString)

Here you can find the source of chop(String aString)

Description

Chops off the very last character of the given string.

License

Open Source License

Parameter

Parameter Description
aString a string to chop

Return

the specified string minus it's last character, or null for null or empty string for a string with length == 0|1.

Declaration

public static String chop(String aString) 

Method Source Code

//package com.java2s;
/*//w ww  . j  a v a2 s  . co  m
 * Copyright (C) 2001-2003 Colin Bell
 * colbell@users.sourceforge.net
 *
 * This library is free 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; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

public class Main {
    /**
     * Chops off the very last character of the given string.
     * 
     * @param aString a string to chop
     * @return the specified string minus it's last character, or null for null
     *         or empty string for a string with length == 0|1.
     */
    public static String chop(String aString) {
        if (aString == null) {
            return null;
        }
        if (aString.length() == 0) {
            return "";
        }
        if (aString.length() == 1) {
            return "";
        }
        return aString.substring(0, aString.length() - 1);
    }
}

Related

  1. chop(double[][] a, double precision)
  2. chop(final String source)
  3. chop(String line)
  4. chop(String s)
  5. chop(String s, int i)
  6. chop(String s, int maxLength)