public String substringBefore ( String string , String pattern ) { if ( string == null || pattern == null ) { return string ; } int pos = string . indexOf ( pattern ) ; if ( pos != - 1 ) { return string . substring ( 0 , pos ) ; } return null ; }
Gets the substring before a given pattern