Java String Sub String substringUntilMatch(String string, String match)

Here you can find the source of substringUntilMatch(String string, String match)

Description

substring Until Match

License

Open Source License

Return

a substring of given string up until the start of the first occurrence of given match, or the whole string if no match is found.

Declaration

public static String substringUntilMatch(String string, String match) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 Bruno Medeiros and other Contributors.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w ww .j  ava2 s . co  m
 *     Bruno Medeiros - initial implementation
 *******************************************************************************/

public class Main {
    /** @return a substring of given string up until the start of the first occurrence of given match, 
     * or the whole string if no match is found. */
    public static String substringUntilMatch(String string, String match) {
        int index = string.indexOf(match);
        return (index == -1) ? string : string.substring(0, index);
    }
}

Related

  1. subStrings(String str1, String str2)
  2. substrings(String[] arr, int start, int end)
  3. subStringToInteger(String src, String start, String to)
  4. substringToLast(final String str, final String separator)
  5. substringUntil(String org, int begin, char term)
  6. subStringWhiteSpaces(String str, int maxLen)
  7. subStringWith3Point(String inputStr, int beginIndex, int length)
  8. subStrOccurences(String str, String findStr)
  9. subStrTime(String strTime)