StringTokenizer st = new StringTokenizer(str,"$");

解决方案 »

  1.   

    The following is one example of the use of the tokenizer. The code:      StringTokenizer st = new StringTokenizer("this is a test");
         while (st.hasMoreTokens()) {
             println(st.nextToken());
         }
     
    prints the following output:      this
         is
         a
         test
     
      

  2.   

    import java.util.StringTokenizer;public class Calc {
      public static void main (String args []) {
         StringTokenizer st = new StringTokenizer("product$price","$");
         while (st.hasMoreTokens()) {
             System.out.println(st.nextToken());
         }
     
      }
    }
      

  3.   

    如果必须得把str赋给str1和str2呢?就不能用while循环了,有没有什么办法?
      

  4.   

    回复人: hexiaofeng(java爱好者) (2001-11-13 16:30:38)  得0分 
    import java.util.StringTokenizer;public class Calc {
      public static void main (String args []) {
        StringTokenizer st = new StringTokenizer("product$price","$");
        String a[] = new String[2];
        int i = 0;
        while (st.hasMoreTokens()) {
            a[i] =  st.nextToken();
            i = i+1;
        }  }
     
      

  5.   

    我也是这么想的,但是如果不知道分成2个,而是要靠$来判断呢?import java.util.StringTokenizer;public class Calc {
      public static void main (String args []) {
        StringTokenizer st = new StringTokenizer("product$price","$");
        String[] str=new String[2];
        int i=0;
        while (st.hasMoreTokens()) {
            str[i]=st.nextToken();
            i++;
        }
        String st1=str[0];
        String st2=str[1];
        System.out.println(str[0]);
        System.out.println(str[1]);
      }
    }
      

  6.   

    Vector v = new Vector() ;while (st.hasMoreTokens()) {
           v.add(st.nextToken());
           
        }
      String st = (String)v.get(0);
      

  7.   

    List pool=new LinkedList();
    StringTokenizer st=new StringTokenizer("product$price","$");while (st.hasMoreTokens()){
      pool.add(st.nextToken());
    }String[] s=(String)pool.toArray();QQ1818477欢迎交流
      

  8.   

    错了!
    刚才代码最后一行应该改为
    Object s=pool.toArray();
    才对呵呵,这不影响程序本身,因为Object是一切类的基类,并且重载了toString()方法
      

  9.   

    又少写了个[]
    Object s[]=pool.toArray();
      

  10.   

    int posiotion=str.indexOf("$");
    str1=str.subString(0,posiotion);
    str2=str.subString(position+1,str.length);