Str 里面有中文分号和英文分号吗?

解决方案 »

  1.   

    用“;”区分
    StringTokenizer st = new StringTokenizer("2003-12-25;0.001mg/cm;通道a;0.002mg/cm;通道b;……;0.00nmg/cm;通道n;", ";");
         while (st.hasMoreTokens()) {
             println(st.nextToken());
         }
      

  2.   

    你的String要有固定的分隔符,然后用StringTokenzer类去处理
      

  3.   

    如果全为英文分号下面程序可以帮你实现
    :(希望高手能改进import java.util.regex.*;
    public class TestStr {
      static Pattern p;
      static String str="2003-12-25;0.001mg/cm;通道a;0.002mg/cm;通道b;……;0.00nmg/cm;通道n;\r";
      static String[] strTest=str.split(";");
      public TestStr() {
      }
      static String getTime(){
       // p=Pattern.compile("^[\\d]{4}\\-[\\d]{2}\\-[\\d]{2}$");
        return strTest[0];
      }
      static String getTag(int index){
        String strTemp="^通道[A-z]{1}$";
        int j=0;
       if (index>strTest.length)
          return "输入非法";
        for(int i=0;i<strTest.length;i++){
          if (Pattern.matches(strTemp,strTest[i]))
            { j++;
              if (j == index)
                return strTest[i];
            }
            continue;
        }
        return "没有你要找的";
      }
      static String getData(int index){
        String strTemp="^0.00"+index+"mg/cm$";
        for(int i=0;i<strTest.length;i++){
          if (Pattern.matches(strTemp,strTest[i]))
            return strTest[i];
          continue;
        }
          return "没有你要找的";  }  public static void main(String[] args) {
        System.out.println(getData(2));
      }}
      

  4.   

    ex:
    String tmp="info-info2-的得-hoho";如果你在tmp里设置了分隔符,例如我这里的是'-'作为分歌符的那么你可以用如下方法:
    String[] str=tmp.split("-");
    会获得如下结果:
    str[0]="info";
    str[1]="info2";
    str[2]="的得";
    str[3]="hoho";