正则表达式
java.lang.String.split()得到String[]的length-1

解决方案 »

  1.   

    splitjdk4.0才有
    String str1 = "11;22;33;33;44;55;66";
    String str2 = ";";
    String []s = str1.split(str2);
    System.out.println("in "+str1+" have "+s.length-1+" "+str2);
      

  2.   

    给你个程序,,,
    是用 正则表达式的
    import java.io.*;
    import java.util.regex.*;public final class WordFinder
    {
        private static String regularExpression;
        private static String wholeContent;
        private static Pattern pattern;
        private static Matcher matcher;
        private static boolean found;    public static void main(String[] argv)
         throws IOException
        {
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

    while(true)
    {
    try
    {
    System.out.print("Your whole content is: ");
    wholeContent = stdin.readLine();
    System.out.print("Your regualar expression is: ");
    regularExpression = stdin.readLine();
         }
         catch (IOException ioe)
         {
         System.err.println(ioe.toString());
         System.exit(-1);
         }         pattern = Pattern.compile(regularExpression);
             matcher = pattern.matcher(wholeContent);
        
         found = false;
            while(matcher.find())
            {
                System.out.println("I found the text \"" + matcher.group() +
                                   "\" starting at index " + matcher.start() +
                                   " and ending at index " + matcher.end() + ".");
                found = true;
            }
            if(!found)
            {
                System.out.println("No match found.");
            }
    }
        }
    }
      

  3.   

    谢谢诸位的鼎立帮助,小弟感激不尽!
    zh_baiyu(SkyBay)的正则表达式更是让小弟有了意外的收获!谢了!