比如以前是String str = 12313.jsp,534.jsp,7556.jsp;
要删除534.jsp
得到新的字符串12313.jsp,7556.jsp
哪位知道怎么写啊

解决方案 »

  1.   

    字符串大概就是 xxx.xxx,yyy.yyy,zzz.zzz这种形式?
      

  2.   

    写个死的                 String str = "12313.jsp,534.jsp,7556.jsp";
    String s=str.substring(0,str.indexOf(","));
    String spare1=str.substring(str.indexOf(",")+1);
    String s2=spare1.substring(spare1.indexOf(","));
    String s3=s+s2;
    System.out.println(s3);
      

  3.   

    要是活动的话 接以“,”号切分字符串用map装起来在删除你想删除的
      

  4.   


    String str = "12313.jsp,534.jsp,7556.jsp";
    System.out.println(str.replaceAll("(?<=,).*,(?!,)",""));
      

  5.   

    说说规律?每次会出现多少个以“,”分隔的内容?每次删除几个?package com.xuz.csdn.worldcup.day13;public class StringSplitTest { /**
     * @param args
     */
    public static void main(String[] args) {
    System.out.println(splitByCount("1.jsp,2.jsp,3.jsp",",",2));
    System.out.println(splitByCount("1.jsp,2.jsp,3.jsp",",",2,3));
    } private static String splitByCount(String str,String regex,int...nums){
    StringBuffer sb = new StringBuffer();

    String[] array = str.split(regex);
    for (int i = 0; i < array.length; i++) {
    if (isContains(nums, i+1) == false) {
    sb.append(array[i]+",");
    }
    }

    String temp = sb.toString();

    return temp.substring(0,temp.length()-1);
    }

    private static boolean isContains(int[] sour,int i){
    for (int j = 0; j < sour.length; j++) {
    if (sour[j] == i) {
    return true;
    }
    }

    return false;
    }
    }
      

  6.   

    private static boolean isContains(int[] sour,int i){
            for (int j = 0; j < sour.length; j++) {
                if (sour[j] == i) {
                    return true;
                }
            }
            
            return false;
        }
    int[] -> List 然后用contains方法亦可。
      

  7.   

     string str = "12313.jsp,534.jsp,7556.jsp";
           string[] s= str.Split(',');
            string ss="";
           if (str.Contains("534.jsp"))
           {
               for (int i = 0; i < s.Length; i++)
               {
                   if (s[i] != "534.jsp")
                   {
                       if (i != s.Length - 1)
                       {
                         ss+=s[i]+",";
                       }
                       else
                       {
                           ss += s[i];
                       }
                   }
               }
           }
      

  8.   


    package com;import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test {
    public static void main(String[] args) {
    String str = "12313.jsp,534.jsp,7556.jsp";
    Matcher matcher = Pattern.compile("(\\S{10})\\S{8}(\\S+)").matcher(str);
    while (matcher.find()) {
    System.out.println(matcher.group(1) + matcher.group(2));
    }
    }}
      

  9.   


    public static void main(String[] args) {
    // 方法1:根据完整名字删除
    String str = "12313.jsp,534.jsp,7556.jsp";
    String delStr = "534.jsp";
    str = str.replaceAll(delStr + ",", "");// 12313.jsp,7556.jsp
    System.out.println(str);

    // 方法2:根据模糊字段删除
    String str2 = "12313.jsp,534.jsp,7556.jsp";
    String delStr2 = "4.js";
    str2 = str2.replaceAll(",?\\w*"+delStr2+"\\w*\\.?\\w*,?", ","); // 12313.jsp,7556.jsp
    System.out.println(str2);
    }
      

  10.   

    str.split(",");循环数组,删除下标为1的数据
      

  11.   

        public static void main(String args[]){
         System.out.println(DeleteWord.delete("1.jsp,2.jsp,3.jsp,3.jsp,3.jsp,777.jsp,3.jsp", "3.jsp"));
        
        }
        public static String delete(String orginal,String target){
         StringBuffer result =new StringBuffer();
         String array[]=orginal.split(",");
         for(int i = 0;i<array.length;i++){
         if(!array[i].equals(target)){
         result.append(array[i]);
         result.append(",");
         }
         }
         return result.toString();
        }