Java String Left left(String str, int len, String appendStrIfOver)

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

Description

left

License

MIT License

Declaration

public static String left(String str, int len, String appendStrIfOver) 

Method Source Code

//package com.java2s;
/*!/*w w w .  ja va2s .com*/
 * mifmi-commons4j
 * https://github.com/mifmi/mifmi-commons4j
 *
 * Copyright (c) 2015 mifmi.org and other contributors
 * Released under the MIT license
 * https://opensource.org/licenses/MIT
 */

public class Main {
    public static String left(String str, int len) {
        return left(str, len, null);
    }

    public static String left(String str, int len, String appendStrIfOver) {
        if (str == null) {
            return null;
        }
        if (str.length() <= len) {
            return str;
        }
        if (appendStrIfOver == null || appendStrIfOver.isEmpty()) {
            return str.substring(0, len);
        } else {
            return str.substring(0, len - appendStrIfOver.length()) + appendStrIfOver;
        }
    }
}

Related

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