删除字符串中的某个字   然后后面的前移动  用什么方法?

解决方案 »

  1.   

    replace成空字符串就可以了
    或者两个substring连接
      

  2.   

    把字符串赋值给StringBuffer 然后用方法deleteCharAt(int index).
      

  3.   


    public class Test {
           public static void main(String[] args) {
              String s="abcde".replace('c',' ');
              String s2[]=s.split(" ");
              for(int i=0;i<s2.length;i++)
                 System.out.print(s2[i]);
        }
    }
      

  4.   

    用replaceAll吧,灵活点,因为可以用正则.
      

  5.   

    有同时多个替换可能的话就用replaceAll("正则","")吧,方便
      

  6.   

    replaceall(‘待处理的字符',"")第二个参数里面什么都不写,空格都不要加
      

  7.   

    StringBuffer里面有删除功能
      

  8.   


    public class Test { public static void main(String[] args) {

     String s = "haha你好啊";
     
     System.out.println(s.replace("你",""));
    }
    }
      

  9.   

    public class Test {
        public static void main(String args[]) {
            char data[] = {'a', 'b', 'c'};
            int j=0;
            for(int i=0;i<data.length;i++) {
                j=i;
                if(data[i]=='a') {
                    while(j>data.length) {
                        data[i]=data[i+1];
                        j++;
                    }                
                }
            }
        }
    }