Java String Sub String subString(String text, String leadingPart)

Here you can find the source of subString(String text, String leadingPart)

Description

gets the substring of the given text reduced by the given leading part.

License

Open Source License

Parameter

Parameter Description
text a parameter
leadingPart a parameter

Return

the reduced substring, if the text starts with the given leading part; otherwise the incoming, unmodified text.

Declaration

public static String subString(String text, String leadingPart) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008 flowr.org - all rights reserved. This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License (EPL) v1.0. The EPL is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: flowr.org - initial API and implementation
 ******************************************************************************/

public class Main {
    /**//from   ww w .j  a  v a  2s  .  co  m
     * gets the substring of the given text reduced by the given leading part.
     *
     * @param text
     * @param leadingPart
     * @return the reduced substring, if the text starts with the given leading part; otherwise the incoming, unmodified
     *         text.
     */
    public static String subString(String text, String leadingPart) {
        if (text.startsWith(leadingPart)) {
            return text.substring(leadingPart.length());
        } else {
            return text;
        }
    }

    /**
     * gets the substring of the given text reduced by the number of leading and tailing characters.
     *
     * @param text the String to reduce
     * @param lead number of characters to remove at the leading end
     * @param tail number of characters to remove at the tailing end
     * @return the reduced substring, reduced by <code>lead</code> chars at the begin and <code>tail</code> chars at the
     *         end.
     * @throws StringIndexOutOfBoundsException
     */
    public static String subString(String text, int lead, int tail) {
        return text.substring(lead, text.length() - tail);
    }
}

Related

  1. substring(String subject, int start, int end)
  2. substring(String text, int begin, int end)
  3. substring(String text, int start, int end)
  4. substring(String text, int startPos, int endPos)
  5. substring(String text, int startPos, int len)
  6. subString(String val, int start, int end)
  7. SubString(String x, long y)
  8. substring(StringBuffer buf, int start, int lim)
  9. substring2ByteString(String str, int endIndex)