java吧 关注:1,291,717贴子:12,821,484
  • 5回复贴,共1

求如何去掉字符串的某些字符

只看楼主收藏回复

char[] c = {'1','2','3','4','5','6','7','8','9','0'};
String b = "asd18ssd3dfda232";
String a = null;
现有一个字符数组 c 和一个字符串 b,我想通过一个字符数组 c 中的内容将字符串 b 中存有字符数组 c中的内容去掉;也就是将b中的数字去掉,并保存到另一个变量中


IP属地:广东1楼2018-08-15 18:03回复
    你是想去掉b中的数字,然后复制给a么?


    IP属地:河北来自Android客户端2楼2018-08-15 18:26
    收起回复
      2025-12-18 21:58:14
      广告
      不感兴趣
      开通SVIP免广告
      char[] c = {'1','2','3','4','5','6','7','8','9','0'};
      String b = "asd18ssd3dfda232";
      String a = "";
      for (int i = 0; i < c.length; i++) {
      String f = String.valueOf(c[i]);
      System.out.println(f);
      if(b.indexOf(f)>0){
      b=b.replaceAll(f, "");
      }
      }
      a=b;
      System.out.println(a);


      IP属地:安徽6楼2018-08-15 21:57
      回复
        根据c建立集合,遍历b中字符逐一判断是否在集合中


        IP属地:北京7楼2018-08-15 22:00
        回复