public static String truncateBeforeSecondOccurrence(String text,String word){
  int pos=text.indexOf(word);
  if (pos == -1)   return text;
  pos=text.indexOf(word,pos + 1);
  if (pos == -1)   return text;
 else   return text.substring(0,pos);
}

public static String truncateBeforeSecondOccurrence ( String text , String word ) { int pos = text . indexOf ( word ) ; if ( pos == - 1 ) return text ; pos = text . indexOf ( word , pos + 1 ) ; if ( pos == - 1 ) return text ; else return text . substring ( 0 , pos ) ; }
removes all of string from the second occurrence of the given word onward
