如何删除后跟特殊字符(#)的单词?例如:从短语:Eva have green#eyes 我想删除单词“green”(Eva have eyes),即以空格结尾的单词。
我也有删除@后面的整行的问题,
例如:Eva have green@eyes
---> 并且应该是“ eyes
”我的代码(我不知道如何完成它):
class Stack {
public Stack() {
del = '&'; //that method deletes only one character
//ex: ab&cd ---> acd
destroy = '@';
delWord = '#';
stack = new Stack<Character>();
}
public void methods(String string)
{
for (int i=0; i< string.length(); i++) //that method deletes only one character
//ex: ab&cd ---> acd
{
if ( del == string.charAt(i) )
{
if (stack.size() > 0)
stack.remove(stack.size()-1);
}
else if( destroy == string.charAt(i) )
{
stack.remove(stack.size());
}
}
}
}