我在java中有一个包含以下字符的字符串..
'2010-12-04' and '2013-12-03' and wwid='1234'
现在根据我的需要,我必须删除它的起始字符,并使其像...
and wwid='1234'
我通过子串概念尝试了它,我试图给出需要删除的起点,之后将其添加到String中但我无法得到它..
请帮我解决这个问题。 提前致谢
答案 0 :(得分:1)
您可以先找到最后一个Indexof String and
,并将其作为子串方法的起始位置。
尝试
String text = "'2010-12-04' and '2013-12-03' and wwid='1234'";
text = text.substring(text.lastIndexOf("and"));
System.out.println(text);
控制台输出:
and wwid='1234'
答案 1 :(得分:1)
答案 2 :(得分:0)
你可以试试这个:
String input = "'2010-12-04' and '2013-12-03' and wwid='1234'"
String myNewString = input.substring(numberOfPositionsToRemove);
在你的情况下,它将是:
String input = "'2010-12-04' and '2013-12-03' and wwid='1234'"
String myNewString = input.substring(30);
或者为了让它更具动感,你可以使用:
String input = "'2010-12-04' and '2013-12-03' and wwid='1234'"
int index = input.lastIndexOf("and");
String myNewString = input.substring(index);
答案 3 :(得分:0)
实际上子字符串应该可以工作。您需要考虑的一件事是子字符串不会更改实际字符串但返回新字符串。所以使用:
String newString = str.substring(30);