Here you can find the source of substringBefore(String string, String delimiter)
Parameter | Description |
---|---|
string | String to get a substring from. |
delimiter | String to search for. |
public static String substringBefore(String string, String delimiter)
//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; } }