xyz xyz - 4 years ago 147
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)


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 Source

look at String.indexOf and String.substring.

Make sure you check for -1 for indexOf.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download