Java Utililty Methods String Chop

List of utility methods to do String Chop

Description

The list of methods to do String Chop are organized into topic(s).

Method

String[]chop(String[] arr, int pos)
chop
String[] res = new String[arr.length - pos];
for (int i = 0; i < arr.length - pos; i++) {
    res[i] = arr[pos + i];
return res;
voidchop(StringBuffer buffer, int chars)
Lobs the last chars off the StringBuffer
int numberToChop = Math.min(buffer.length(), chars);
buffer.delete(buffer.length() - numberToChop, buffer.length());
StringchopAccelerator(final String title)
chop Accelerator
int startPos = title.indexOf("\\t");
if (startPos > 0) {
    return title.substring(0, startPos);
return title;
StringChopAllLf(String this_string, String chomp_off)
Chop All Lf
if (!this_string.contains(chomp_off))
    return this_string;
return ChopLf(this_string, chomp_off, SeekRt(this_string, chomp_off.charAt(0)) + this_string.length() + 1);
StringChopAllRt(String this_string, String chomp_off)
Chop All Rt
if (!this_string.contains(chomp_off))
    return this_string;
return this_string.substring(0, this_string.length() - SeekLf(this_string, chomp_off.charAt(0)));
StringchopBraces(String s)
Removes '[' and ']' from beginning and end of a String, but only if both are present.
if (s.startsWith(STRSQBRACKETSTART) && s.endsWith(STRSQBRACKETEND))
    return s.substring(1, s.length() - 1);
return s;
String[]chopCommentFromArgs(String[] args)
chop Comment From Args
if (args == null) {
    return null;
int commentStart = -1;
for (int i = 0; i < args.length; i++) {
    if (args[i] != null && args[i].startsWith("//")) {
        commentStart = i;
        break;
...
StringchopExt(String orig)
chop Ext
int lastDot = orig.lastIndexOf('.');
return lastDot < 0 ? orig : orig.substring(0, lastDot);
StringchopFirstComponent(String s)
Returns the string s with the first component removed.
int dotIx = s.indexOf('.');
return dotIx < 0 ? s : s.substring(1 + dotIx);
floatchopFractionalPart(float original, int no_of_digits )
Limitation: (original * 10^no_of_digits) has to fit in a signed integer (java integers are 32bit)
int mult = __chopFractionalPart_lookup[no_of_digits];
return Math.round(original * mult) / (float) mult;