【发布时间】:2017-11-16 09:09:28
【问题描述】:
我想从输入字符串中选择特定的子字符串:
String i = "example/test/foo-foo";
如何仅获取子字符串foo-foo 作为新字符串?
预期输出:
String newString = "foo-foo";
【问题讨论】:
-
你有看过
String提供的方法吗? -
int index = i.lastIndexOf("/");字符串名称= i.substring(index + 1);
-
String i = "example/test/foo-foo"; String[] temp = i.split("/"); System.out.println(temp[temp.length-1]);