Java String Sub String substringBefore(String string, String delimiter)

Here you can find the source of substringBefore(String string, String delimiter)

Description

Returns the substring before the first occurrence of a delimiter.

License

Open Source License

Parameter

Parameter Description
string String to get a substring from.
delimiter String to search for.

Return

Substring before the first occurrence of the delimiter.

Declaration

public static String substringBefore(String string, String delimiter) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from ww w.j a  va2 s .  c o  m*/
    * Returns the substring before the first occurrence of a delimiter. The
    * delimiter is not part of the result.
    *
    * @param string    String to get a substring from.
    * @param delimiter String to search for.
    * @return          Substring before the first occurrence of the delimiter.
    */
    public static String substringBefore(String string, String delimiter) {
        int pos = string.indexOf(delimiter);
        return pos >= 0 ? string.substring(0, pos) : string;
    }
}

Related

  1. substringBefore(String s, char c)
  2. substringBefore(String str, int endChar)
  3. substringBefore(String str, String separator)
  4. substringBefore(String str, String separator)
  5. substringBefore(String str, String separator)
  6. substringBefore(String text, String str)
  7. substringBeforeChar(String str, int separator)
  8. substringBeforeFirst(String string, String delimiter)
  9. subStringBeforeFirstTab(final String s)