I have a string (which is basically a file name following a naming convention) abc.def.ghi
abc.def.ghi
I would like to extract the substring before the first
If your project already uses commons-lang, StringUtils provide a nice method for this purpose:
String filename = "abc.def.ghi"; String start = StringUtils.substringBefore(filename, "."); // returns "abc"
see javadoc [2.6] [3.1]