????str??str.substring(int beginIndex);?????str????????????beginIndex????????????????????????str??
????str??str.substring(int beginIndex??int endIndex);???str?д?beginIndex????endIndex???????????????????丳???str;
????????????????????
public class StringDemo{
public static void main(String agrs[]){
String str="this is my original string";
String toDelete=" original";
if(str.startsWith(toDelete))
str=str.substring(toDelete.length());
else
if(str.endsWith(toDelete))
str=str.substring(0?? str.length()-toDelete.length());
else
{
int index=str.indexOf(toDelete);
if(index!=-1)
{
String str1=str.substring(0?? index);
String str2=str.substring(index+toDelete.length());
str=str1+str2;
}
else
System.out.println("string /""+toDelete+"/" not found");
}
System.out.println(str);
}
}
????????:str??str.substring(int beginIndex??int endIndex);???????????:
????beginIndex =< str??? < endIndex
??????????????????????????????????
??????????API?п????????????
?????????????????????????????????????????????????????????????
????substring
????public String substring(int beginIndex??
????int endIndex)
???????????????????????????????????????????????????????????? beginIndex ?????????????? endIndex - 1 ???????????????????????????? endIndex-beginIndex??
?????????????
????"hamburger".substring(4?? 8) returns "urge"
????"smiles".substring(1?? 5) returns "mile"
??????????
????beginIndex - ????????????????????
????endIndex - ????????????????????????
?????????
??????????????????
?????????
????IndexOutOfBoundsException - ???? beginIndex ??????? endIndex ????? String ??????????? beginIndex ???? endIndex??