Alex Rivera | Logout

Split string with dot as delimiter

Asked 2010-08-02T12:17:01.523
131

I am wondering if I am going about splitting a string on a . the right way? My code is:

String[] fn = filename.split(".");
return fn[0];

I only need the first part of the string, that's why I return the first item. I ask because I noticed in the API that . means any character, so now I'm stuck.

Edit
Report

1 Answer

3

Wouldn't it be more efficient to use

 filename.substring(0, filename.indexOf("."))

if you only want what's up to the first dot?

answered 2010-08-02T12:22:35.080

Your Answer