Java String Left left(String str, int len)

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

Description

left

License

Open Source License

Declaration

public static String left(String str, int len) 

Method Source Code

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

public class Main {
    public static String left(String str, int len) {
        return (str == null) ? null : ((len < 0) ? "" : ((str.length() <= len) ? str : str.substring(0, len)));
    }//from   www.  ja  va  2s .c o m

    public static int length(String str) {
        return str == null ? 0 : str.length();
    }

    public static String substring(String str, int start) {
        if (str == null)
            return null;

        if (start < 0)
            start = str.length() + start;
        if (start < 0)
            start = 0;

        return (start > str.length()) ? "" : str.substring(start);
    }

    public static String substring(String str, int start, int end) {
        if (str == null)
            return null;

        if (end < 0)
            end = str.length() + end;
        if (start < 0)
            start = str.length() + start;
        if (end > str.length())
            end = str.length();
        if (start > end)
            return "";
        if (start < 0)
            start = 0;
        if (end < 0)
            end = 0;

        return str.substring(start, end);
    }
}

Related

  1. left(String source, int length)
  2. left(String source, String searchFor)
  3. left(String source, String searchFor)
  4. left(String str, int count)
  5. left(String str, int len)
  6. left(String str, int len)
  7. left(String str, int len)
  8. left(String str, int len, String appendStrIfOver)
  9. left(String str, int length)