62,612
社区成员
发帖
与我相关
我的任务
分享
public class test9 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s1="Tom is 25 years old,he likes football.";
String s2="he likes football.";
int begin=s1.indexOf(s2);
int end=begin+s2.length();
System.out.println(s1.substring(begin, end));
}
}
String str = "Tom is 25 years old,he likes football.Tom is 25 years old,he likes reading books";
String replaceAll = str.replaceAll("Tom is 25 years old,", "");//把不需要的字符串替换掉
System.out.println(replaceAll);