Java String Sub String substringBefore(String str, String separator)

Here you can find the source of substringBefore(String str, String separator)

Description

substring Before

License

Open Source License

Return

the the substring before the first occurrence of a separator.

Declaration

public static String substringBefore(String str, String separator) 

Method Source Code

//package com.java2s;
// BSD-style license that can be found in the LICENSE file.

public class Main {
    /**/*from  w  ww  .  j  a  v a 2  s  .  c  o m*/
     * @return the the substring before the first occurrence of a separator.
     */
    public static String substringBefore(String str, String separator) {
        int index = str.indexOf(separator);
        if (index == -1) {
            return str;
        }
        return str.substring(0, index);
    }
}

Related

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