how to achieve string.split() method in Jdk1.3?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chindanoor
    New Member
    • Apr 2007
    • 13

    how to achieve string.split() method in Jdk1.3?

    As i used split method in my local Machine(jdk1.4) it was working fine.., When i try to use in the server(which is jdk1.3 version) unable to support it..,

    As i m able to do it with StringTokenizer but it was not considering the Gaps..,

    Example:

    String Str="1,XYZ,Delt astreet,,US";

    when i use in split method by giving split(",");work ing fine and storing a array.

    if i try to use the following code.., it was storing null..,

    StringTokenizer st=new StringTokenizer (str,",");
    int count=st.countT okens();
    String Array[]=new String[count];
    for(;i<count;i+ +)
    {
    Array[i] = st.nextToken();
    }
    for(int k=0;k<count;k++ )
    {
    System.out.prin tln(Array[k]);
    }

    My output should be same as the input.., and it should store ",," also... but it unable to do that..,

    Can anybody please help this as i m in very urgency..,

    Thanks in Advance....
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by chindanoor
    As i used split method in my local Machine(jdk1.4) it was working fine.., When i try to use in the server(which is jdk1.3 version) unable to support it..,

    As i m able to do it with StringTokenizer but it was not considering the Gaps..,

    Example:

    String Str="1,XYZ,Delt astreet,,US";

    when i use in split method by giving split(",");work ing fine and storing a array.

    if i try to use the following code.., it was storing null..,

    StringTokenizer st=new StringTokenizer (str,",");
    int count=st.countT okens();
    String Array[]=new String[count];
    for(;i<count;i+ +)
    {
    Array[i] = st.nextToken();
    }
    for(int k=0;k<count;k++ )
    {
    System.out.prin tln(Array[k]);
    }

    My output should be same as the input.., and it should store ",," also... but it unable to do that..,

    Can anybody please help this as i m in very urgency..,

    Thanks in Advance....
    Here is the spec for it.

    Comment

    • chindanoor
      New Member
      • Apr 2007
      • 13

      #3
      hi i m able to find it through Stringtokenizer .., but it unable to store the Spaces ..,

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by chindanoor
        hi i m able to find it through Stringtokenizer .., but it unable to store the Spaces ..,
        Can you post the complete code that you used for it?

        Comment

        • chindanoor
          New Member
          • Apr 2007
          • 13

          #5
          string str="ONECHRG,H0 2013,180573,Voi ce Port,BDR Product,BDR Product,BRIGHTO N: 20002530,INSTAL LATION CHARGE,2005-07-01-00.00.00.000000 ,,,GBP";
          StringTokenizer st=new StringTokenizer (str,",");
          int count=st.countT okens();
          String Array[]=new String[count];
          for(;i<count;i+ +)
          {
          Array[i] = st.nextToken();
          }

          but values are not storing in appropriate order when i try to retirve it those are in the correct order..,
          as i marked in bold which there are few spaces ",,," which troubling me..,

          Comment

          • AdilJ
            New Member
            • Jan 2013
            • 1

            #6
            Use this to split even in JDK1.3

            Code:
            import java.util.StringTokenizer;
            public class ListTest {
             public static void main(String[] args) {
            String str="ONECHRG,H02013,180573,Voice Port,BDR Product,BDR Product,BRIGHTON: 20002530,INSTALLATION CHARGE,2005-07-01-00.00.00.000000,,,GBP";
            StringTokenizer st=new StringTokenizer(str,",");
            int count=st.countTokens();
            String Array[]=new String[count];
            int i =0;
            while(st.hasMoreTokens())
            {
            Array[i] = st.nextToken();
            System.out.println(Array[i]);
            i++;
            }
            
            }
            }
            This is your code but somewhat modified...

            Adil
            Last edited by Rabbit; Jan 28 '13, 04:56 PM. Reason: Email removed per forum policy. Please use code tags when posting code.

            Comment

            Working...