Java String Left left(String baseString, int pos)

Here you can find the source of left(String baseString, int pos)

Description

left

License

LGPL

Declaration

public static String left(String baseString, int pos) 

Method Source Code

//package com.java2s;
/**//  w w w .j  a va  2  s. c  om
* Converts a line of text into an array of lower case words using a
* BreakIterator.wordInstance().
* <p>
* 
* This method is under the Jive Open Source Software License and was written
* by Mark Imbriaco.
* 
* @param text
*          a String of text to convert into an array of words
* @return text broken up into an array of words.
*/

public class Main {

    public static String left(String baseString, int pos) {
        int diLength;
        if (baseString == null || pos <= 0) {
            return null;
        } else {
            diLength = baseString.length();
            if (diLength < pos) {
                return baseString.substring(0);
            } else {
                return baseString.substring(0, pos);
            }
        }
    }

    public static final int length(String baseString) {
        if (baseString == null)
            return 0;
        else
            return baseString.length();
    }

    public static final String substring(String baseString, int start, int end) {
        if (baseString == null)
            return null;
        else if (start >= baseString.length() || start < 0 || end < 0 || start > end)
            return null;
        else if (end >= baseString.length())
            return baseString.substring(start);
        else {
            return baseString.substring(start, end);
        }
    }

    public static final String substring(String baseString, int start) {
        if (baseString == null)
            return null;
        else
            return substring(baseString, start, baseString.length());
    }
}

Related

  1. left(final String s, final int len)
  2. left(final String string, final int length)
  3. left(final String text, final String sep)
  4. left(Object src, int length, String defaultValue)
  5. left(String s, int l)
  6. left(String s, int len)
  7. left(String s, int nCaratteri)
  8. left(String s, int size)