Here you can find the source of substringBefore(String str, String separator)
public static String substringBefore(String str, String separator)
//package com.java2s; //License from project: Apache License public class Main { private static final int INDEX_NOT_FOUND = -1; private static final String EMPTY = ""; public static String substringBefore(String str, String separator) { if (isEmpty(str) || separator == null) { return str; }//from w w w.jav a 2 s. c o m if (separator.length() == 0) { return EMPTY; } int pos = str.indexOf(separator); if (pos == INDEX_NOT_FOUND) { return str; } return str.substring(0, pos); } public static boolean isEmpty(String str) { return str == null || str.length() == 0; } }