String ar1 = "ABC#ABCD#ABCDEF#ABCDEFG";
String ar2 = "ABC";要的结果:用户输入ABC
结果:ABCD#ABCDEF#ABCDEFG"
用户输入:ABCD
ABC#ABCDEF#ABCDEFG
用户输入:ABCDEF
ABC#ABCD#ABCDEFG
用户输入:ABCDEFG
ABC#ABCD#ABCDEFar1 没有长度限制请高手帮帮忙,谢谢呀
小弟没有分数了

解决方案 »

  1.   

    这题看不太明白,好象输入的内容与arg1、arg2,还有输出的内容之间没有什么共同点。
      

  2.   

    这个arg2是用户输入的内容,我只是给他写死了,这个可以随便变的
      

  3.   

    这个arg2是用户输入的内容,我只是给他写死了,这个可以随便变的
    删除功能:找到对应个给把用户输入的给删除掉
    修改功能:找到对应的字符串,如:ABCD#ABCDEF#ABCDEFG"
    用户输入的是:ABCD
    AIX#ABCDEF#ABCDEFG"
      

  4.   

    String[] args = ar1.split("#");
    读入的字符串 ar2比较后打印出来就ok了
      

  5.   


    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    public class Temp
    {
    public static void main(String[] args)throws IOException 
    {
    String ar1 = "ABC#ABCD#ABCDEF#ABCDEFG";
    String ar2 = null;
    System.out.println("please input arg2:");
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    ar2 = reader.readLine(); 
    Temp tp = new Temp();
    System.out.println(tp.wipe(ar1,ar2));
    }

    private String wipe(String arg1,String arg2)
    {
    String result="";
    if(null!=arg2&&!"".equals(arg2))
    result=arg1.toUpperCase().replace(arg2.toUpperCase()+"#", "");
    else
    result=arg1;
    return result;
    }
    }
      

  6.   

    ar1参数如果始终是xxx#xxxx#这种有规律的数据,应该可以.
      

  7.   

            他指把AIX修改了,假如你输入的是ABCDEFG他的数据不变
      

  8.   

     public class test{
         public static String showStr(String str,String str1){
           String st="";
           if(str!=null&&!str.equals("")){
           String newstr[]=str.split("#");
           String yy=test.getString(newstr, str1);
           if(yy!=null&&!yy.equals("")){
           for(int i=0;i<newstr.length;i++){
           if(i!=Integer.parseInt(yy)){
               if(i!=newstr.length-1){
             st+=newstr[i]+"#";
              }else{ 
               st+=newstr[i];
              }
           }
           }
           }else{
           for(int i=0;i<newstr.length;i++){
           if(i!=newstr.length-1){
                   st+=newstr[i]+"#";
               }else{
                st+=newstr[i];
               }
           }
             }
           }
           return st;
      }
         public static String  getString(String[] str,String str1){
          String tt="";
          if(str!=null&&str.length>0){
             for(int i=0;i<str.length;i++){
                if(str1.equals(str[i])){
                 tt= String.valueOf(i);
                }
             }
          }
          return tt;
          }
         
         public static void main(String arg[]){
              System.out.println(test.showStr("ABC#ABCD#ABCDEF#ABCDEFG", "ABCD"));
         }
      }
    怎么感觉和别人写的代码就是有差距呢?唉!!努力!
      

  9.   

    你是指要替换吗?
    将ar1中字符串中含有用户输入字符串的部分替换成AIX?是不是这个意思?
      

  10.   

    1、把ar1里的#,替换成##
    2、在ar1的开始、结尾,加#
    3、把ar2的开始、结尾,加#
    4、ar1中,替换掉ar2
    5、ar1中的##,替换成#
    6、去掉ar1的两头的#
      

  11.   

    public class test {
    public static String ar1 = "ABC#ABCD#ABCDEF#ABCDEFG"; 
    public static String ar2 = "ABCDEF"; 
    public static void main(String[] args) {
    String[] tempStrs = ar1.split("#");
    String tempStr = "";
    int count = 0;
    for (int i = 0; i < tempStrs.length; i++) {
    if(ar2.equals(tempStrs[i])){
    continue;
    }else{
    if(count == 0){
    tempStr = tempStrs[i];
    }else{
    tempStr = tempStr+"#"+tempStrs[i];
    }
    count++;
    }
    }
    System.out.println(tempStr);
    }
    }
      

  12.   


    public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    String ar1 = "ABC#ABCD#ABCDEF#ABCDEFG";
    List<String> list=new ArrayList<String>();
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    String str=br.readLine();
    String []string=ar1.split("#");
    for(int i=0;i<string.length;i++){
    if(str.equals(string[i])){
    continue;
    }else{
    list.add(string[i]);
    if(i!=string.length-1){
    list.add("#");
    }
    }
    }
    for(Object o:list){
    System.out.print(o);
    }
    }
      

  13.   


    class StudyDate1
    {
    public static void main(String args[])
    {
    String ar1 = "ABC#ABCD#ABCDEF#ABCDEFG";
    String ar2 = "ABC";
    System.out.println(CheckStr(ar2,ar1));
    }
    /* @Describe: 返回字符串不出现用户输入的字符串
    * @param  
    *   str : 需要掉去的字符串
    *   oldStr : 原始字符串
    *   @return newString
    */
    public static String CheckStr(String str,String oldStr)
    {
    String newString = "";

    /*储放以'#'分开的每一个字符串*/
    String tmpStr[] = oldStr.split("#");
    for(String s : tmpStr)
    {
    if(!s.equals(str))
    {
    newString += s+"#";
    }

    }
    return newString;
    }
    }
      

  14.   

    StringBuffer sb=new StringBuffer("ABC#ABCD#ABCDEF#ABCDEFG");
    Scanner input=new Scanner(System.in);
    System.out.println("输入字符串:");
    String str=input.next();
    int index=sb.indexOf(str+"#");
    sb.replace(index,index+str.length()+1,"");
    System.out.println(sb);
      

  15.   


    StringBuffer sb=new StringBuffer("ABC#ABCD#ABCDEF#ABCDEFG"); 
    Scanner input=new Scanner(System.in); 
    System.out.println("输入字符串:"); 
    String str=input.next(); 
    int index=sb.indexOf(str+"#"); 
    sb.replace(index,index+str.length()+1,""); 
    System.out.println(sb);
      

  16.   

    29楼的输入ABCDEFG 会报错的
      

  17.   


    String ar1 = "ABC#ABCD#ABCDEF#ABCDEFG";
    String ar2 = "ABC";
    ar1 = "#"+ar1+"#";

    // System.out.println(ar1.replaceAll("#ABC#", "#"));
    ar1 = ar1.replaceAll("#ABC#", "#");
    ar1 = ar1.replaceAll("^#", "");
    ar1 = ar1.replaceAll("#$", "");
    System.out.println(ar1);
      

  18.   

    你的例子很好用,如果我要修改一个数据那
    ABC#ABCDEF#ABCDEFG
    问题:输入ABC,将要改的数据时:UNIX
    结果:UNIX#ABCDEF#ABCDEFG