在字符串:/lks/koa/lks_news.nsf/VD_Portlet_View?ReadViewEntries&PreFormat&Count=2&RestrictToCategory=%u516C%u53F
中,怎么找到Count=2这个字符呢?

解决方案 »

  1.   

    int index=indexOf("Count=2");
      

  2.   

    我是要找到后还要改变Count=2 的值 比如把2 改成3
      

  3.   

    单独的String的话!public class test { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    String str = "===Count=2=="; int ind = str.indexOf("Count=2");
    if (ind != -1) {
    str = str.substring(ind, ind + 7);
    }
    System.out.println(str);
    }}(2)如果是url的话!我们可以用request.getparameter(Count)
      

  4.   

    用str.replaceFirst("Count=2", "Count=3");
    或者其他的方法看需求了!
    public class test { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    String str = "===Count=2==";

    String strRet = ""; int ind = str.indexOf("Count=2");
    if (ind != -1) {
    strRet = str.substring(ind, ind + 7);

    str = str.replaceFirst("Count=2", "Count=3");
    }
    System.out.println(str);
    }}
      

  5.   

    String strcount = "/lks/koa/lks_news.nsf/VD_Portlet_View?ReadViewEntries&PreFormat&Count=2&RestrictToCategory=%u516C%u53F
    ";
    String str = "Count=2";int index = strcount.indexOf(str);
    if (index>=0)
    {
    str = "Count=3";
    int ind = strcount.indexOf(str);
    }
      

  6.   

    indexOf()
    是查找他的位置吗
      

  7.   

    Count=2
    这个2是一个变量。我怎么把我是要修改的
      

  8.   

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test2 {
      public static void main(String[] args) {
        String strcount = "/lks/koa/lks_news.nsf/VD_Portlet_View?" +
            "ReadViewEntries&PreFormat&Count=2&" +
            "RestrictToCategory=%u516C%u53F";
        Pattern pattern = Pattern.compile("(&Count\\=)\\d+(&)");
        Matcher matcher = pattern.matcher(strcount);
        matcher.find();
        int modify = 3;
        strcount = strcount.substring(0, matcher.end(1)) + modify + 
            strcount.substring(matcher.start(2));
        System.out.println(strcount);
      }
    }