469,276 Members | 1,758 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,276 developers. It's quick & easy.

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,Deltastreet,,US";

when i use in split method by giving split(",");working 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.countTokens();
String Array[]=new String[count];
for(;i<count;i++)
{
Array[i] = st.nextToken();
}
for(int k=0;k<count;k++)
{
System.out.println(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....
May 1 '07 #1
5 4372
r035198x
13,262 8TB
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,Deltastreet,,US";

when i use in split method by giving split(",");working 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.countTokens();
String Array[]=new String[count];
for(;i<count;i++)
{
Array[i] = st.nextToken();
}
for(int k=0;k<count;k++)
{
System.out.println(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.
May 1 '07 #2
hi i m able to find it through Stringtokenizer.., but it unable to store the Spaces ..,
May 1 '07 #3
r035198x
13,262 8TB
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?
May 1 '07 #4
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];
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..,
May 1 '07 #5
AdilJ
1
Use this to split even in JDK1.3

Expand|Select|Wrap|Line Numbers
  1. import java.util.StringTokenizer;
  2. public class ListTest {
  3.  public static void main(String[] args) {
  4. String str="ONECHRG,H02013,180573,Voice Port,BDR Product,BDR Product,BRIGHTON: 20002530,INSTALLATION CHARGE,2005-07-01-00.00.00.000000,,,GBP";
  5. StringTokenizer st=new StringTokenizer(str,",");
  6. int count=st.countTokens();
  7. String Array[]=new String[count];
  8. int i =0;
  9. while(st.hasMoreTokens())
  10. {
  11. Array[i] = st.nextToken();
  12. System.out.println(Array[i]);
  13. i++;
  14. }
  15.  
  16. }
  17. }
This is your code but somewhat modified...

Adil
Jan 28 '13 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Stu Cazzo | last post: by
5 posts views Thread by Blue Ocean | last post: by
reply views Thread by s | last post: by
11 posts views Thread by Carlos Ribeiro | last post: by
8 posts views Thread by ronrsr | last post: by
17 posts views Thread by AMP | last post: by
11 posts views Thread by BigZero | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.