Java String Chop chopLast(String value, int chars)

Here you can find the source of chopLast(String value, int chars)

Description

CHOP LAST

License

Open Source License

Declaration


public static String chopLast(String value, int chars) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// w w w .j  av  a 2  s .  com
     * CHOP LAST
     */

    public static String chopLast(String value, int chars) {
        if (chars < 0 || chars > value.length())
            throw new IllegalArgumentException("invalid chars: " + chars + " / " + value.length());
        return value.substring(0, value.length() - chars);
    }

    public static StringBuilder chopLast(StringBuilder value, int chars) {
        if (chars < 0 || chars > value.length())
            throw new IllegalArgumentException("invalid chars: " + chars + " / " + value.length());
        value.setLength(value.length() - chars);
        return value;
    }
}

Related

  1. chopExt(String orig)
  2. chopFirstComponent(String s)
  3. chopFractionalPart(float original, int no_of_digits )
  4. chopId(String name)
  5. chopIfMatch(StringBuilder sb, char ch)
  6. chopLenghtyString(String title, int maxLen)
  7. chopLongLinesAtSpaces(int maxLineLenght, String text)
  8. chopNull(String str)
  9. chopPrefix(String x, String prefix)