String s = "This is my second original string!";
String toDel = "original";
if(s.startsWith(toDel))
s = s.substring(toDel.length());
else
if(s.endsWith(toDel))
s = s.substring(0,s.length() - toDel.length());
else
{
int index = s.indexOf(toDel); //IndexOf 方法 返回 String 对象内第一次出现子字符串的字符位置。
if(index != -1) {
String s1 = s.substring(0,index);
String s2 = s.substring(index+toDel.length());
s = s1 + s2;
}
else
System.out.println("String: "+toDel+" not be found!");
}
System.out.println(s);
String sr = "This is my third string!";
String sx= "is";
int index = sr.indexOf(sx);
System.out.println(index);
int index2 = sr.indexOf(sx,3);
System.out.println(index2);
}
}