Java String Sub String substring(String string, int maxChars, String suffix)

Here you can find the source of substring(String string, int maxChars, String suffix)

Description

substring

License

Open Source License

Declaration

public static String substring(String string, int maxChars, String suffix) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Robert "Unlogic" Olofsson (unlogic@unlogic.se).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0-standalone.html
 ******************************************************************************/

public class Main {
    public static String substring(String string, int maxChars, String suffix) {

        if (string.length() > maxChars) {
            return string.substring(0, maxChars - 1) + suffix;
        }/*from w w  w .j  a v a 2  s  . co m*/

        return string;
    }
}

Related

  1. substring(String str, int toCount, String more)
  2. substring(String str, String delim)
  3. subString(String string, int beginIndex, int length)
  4. subString(String string, int index)
  5. substring(String string, int init, int end)
  6. substring(String string, int start, int length)
  7. substring(String string, String beginning, String end)
  8. subString(String string, String inizio, String fine)
  9. substring(String subject, int start, int end)