两个办法,一是用字符串替换,将S1中含S2的字符替换成空串!
二是在S1中查找字符串2,然后从找到的位置开始取子串!

解决方案 »

  1.   

    String s1="AAABBB";
    String s2="AAA";
    s1 = s1.replaceAll(s2,"");
    System.out.println(s1);
      

  2.   

    楼主的意思是不是想 比较str1中是否包含str2,如果包含就打印出除str2之外的 str1的其余内容阿?
    我自己写了一个实现这个功能的程序 public class StrCom 
    {
      
      static String s1 = "AAABBB";
      static String s2 = "AAA";
      
      public StrCom() 
      {
      }
      
      public void StrMak(String str1,String str2)
      {
        int a = str1.indexOf(str2);
        if (a != -1)
        {
          int b  = str2.length();
          String res ;
          if(a == 0)
          {
            res = str1.substring(b);
          }
          else
          {
              res = str1.substring(0,a) + str1.substring(a+b);
          }
          System.out.println(res);
        }
        else
        {
            System.out.print("str1 doesn't have str2");
        }
      }
      
      public static void main (String args[])
      {
         StrCom test = new StrCom();
         test.StrMak(s1,s2);
      }
    }