Java String Left left(String str, int size)

Here you can find the source of left(String str, int size)

Description

left

License

Apache License

Declaration

public static String left(String str, int size) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String left(String str, int size) {
        if (str == null || "".equals(str)) {
            return str;
        }//from   ww w  . j  a  va  2  s  .c o m
        if (size > 0) {
            if (size > str.length()) {
                return str;
            } else {
                return str.substring(0, size);
            }
        } else if (size == 0) {
            return "";
        } else {
            size = -size;
            if (size > str.length()) {
                return str;
            }
            return str.substring(str.length() - size);
        }
    }
}

Related

  1. left(String str, int len)
  2. left(String str, int len)
  3. left(String str, int len)
  4. left(String str, int len, String appendStrIfOver)
  5. left(String str, int length)
  6. left(String string, int length)
  7. left(String text, int len)
  8. left(String text, int max)
  9. left(String value, int length)