Split string with dot as delimiter

后端 未结 13 2568
死守一世寂寞
死守一世寂寞 2020-11-22 11:14

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];
         


        
13条回答
  •  甜味超标
    2020-11-22 12:10

    Wouldn't it be more efficient to use

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

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

提交回复
热议问题