Split string with dot as delimiter

后端 未结 13 2211
死守一世寂寞
死守一世寂寞 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:14

    split() accepts a regular expression, so you need to escape . to not consider it as a regex meta character. Here's an example :

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

提交回复
热议问题