Java String Sub String subString(String input, String startStr, String endStr)

Here you can find the source of subString(String input, String startStr, String endStr)

Description

sub String

License

Open Source License

Declaration

public static String subString(String input, String startStr, String endStr) 

Method Source Code

//package com.java2s;
/*/*w  w  w. j  a va 2 s  .  c o m*/
 * Copyright (c) 1996-2001
 * vnxtele Corporation - VAS Center
 * @author ShadowMan - vnxtele Mobile Networks - VAS
 * @version 1.0, 25 January 2012
 * All rights reserved.
 *
 * This software is distributed under vnxtele Open Source License Version 1.0
 * ("Licence Agreement"). You shall use it and distribute only in accordance
 * with the terms of the License Agreement.
 *
 */

public class Main {
    public static String subString(String input, String startStr, String endStr) {
        try {
            int idxStart = input.indexOf(startStr);
            if (idxStart == -1)
                return "";
            int idxEnd = input.indexOf(endStr, idxStart + 1 + startStr.length());
            if (idxStart == -1 || idxEnd == -1)
                return "";
            return input.substring(idxStart + startStr.length(), idxEnd).trim();
        } catch (Exception ex) {
        }
        return "";
    }
}

Related

  1. substring(String baseString, int start, int end)
  2. subString(String input, char start, char end)
  3. substring(String input, int expectedLength)
  4. substring(String input, int maxLength)
  5. substring(String input, int maxLength)
  6. subString(String name)
  7. substring(String origin, int len)
  8. subString(String original, String regex)
  9. subString(String parentStr, String startStr, String endStr)