請讓我知道如何刪除感嘆號之前的單詞。刪除字符串中的感嘆號之前的字符
意味着,例如,如果SRING是
BIM!A , i need only A
SAM!B , i need only B
SNNJ!D , I need only D
請讓我知道如何刪除感嘆號之前的單詞。刪除字符串中的感嘆號之前的字符
意味着,例如,如果SRING是
BIM!A , i need only A
SAM!B , i need only B
SNNJ!D , I need only D
System.out.println(s.substring(s.indexOf("!") + 1));
你可以做一個String
內搜索與
Strings s = "ABD!A";
//This gives you the index of the first !
int i = s.indexOf('!');
//now you can Substring
String after = s.substring(i+1);
System.out.println(str.substring(s.lastIndexOf("!") + 1));
這將打印字符串的部分也就是最後感嘆號之後存在。打印整個字符串,如果沒有「!」有沒有
哪部分會被退回? – Mordechai
@ awolfe91,添加到javadoc的鏈接,希望你不介意;) – 2012-12-05 07:01:47
@RC,沒有一點!謝謝! – awolfe91