Java String Chop chop(String str)

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

Description

chop

License

Open Source License

Declaration

public static String chop(String str) 

Method Source Code

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

public class Main {
    public static String chop(String str) {
        if (str == null) {
            return null;
        }//from w  w w.  j  a  va 2 s  .  co  m
        int strLen = str.length();
        if (strLen < 2) {
            return "";
        }
        int lastIdx = strLen - 1;
        String ret = str.substring(0, lastIdx);
        char last = str.charAt(lastIdx);
        if (last == '\n') {
            if (ret.charAt(lastIdx - 1) == '\r') {
                return ret.substring(0, lastIdx - 1);
            }
        }
        return ret;
    }
}

Related

  1. chop(String line)
  2. chop(String s)
  3. chop(String s, int i)
  4. chop(String s, int maxLength)
  5. chop(String src, String delim)
  6. chop(String str)
  7. chop(String str)
  8. chop(String str)
  9. chop(String str)