xyz xyz - 3 months ago 11
Java Question

In java how to get substring from a string till a character c?

I have a string (which is basically a file name following a naming convention)

abc.def.ghi


I would like to extract the substring before the first
.
(ie a dot)

In java doc api, I can't seem to find a method in String which does that.

Am I missing something? How to do it?

Answer

look at String.indexOf and String.substring.

Make sure you check for -1 for indexOf.