Splitting a String in Java with underscore as delimiter

后端 未结 7 1108
野的像风
野的像风 2021-01-13 00:49

I have the following String (This format for the string is generic)

abc_2012-10-18-05-37-23_prasad_hv_Complete

I want to extract only

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-13 01:18

    This will work even when you have many number of underscore characters in the string you wanted.

    str.substring(str.indexOf("_", str.indexOf("_") + 1) + 1, str.lastIndexOf("_"));
    

提交回复
热议问题