我必须用下划线分割一个字符串。字符串可能有许多下划线,但是我必须用下划线将其分开。如何使用正则表达式使用简单的拆分方法来做到这一点?
您可以使用lastIndexOf
在String
返回您caracters链中最后一次出现的索引。
String thing = "132131_12313_1321_312";
int index = thing.lastIndexOf("_");
String yourCuttedString = thing.substring(0, index);
-1
如果在字符串中未找到该事件,它将返回。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句