• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to String array

 
Angela Jessi
Ranch Hand
Posts: 428
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have String abc = "Hello this is test"
I want to store String into String Array called
String [] xyx = new String[abc.length()]
How can I do?
Thanks in advance
angela
 
Pat Barrett
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this....

hth
Pat B.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean one character at a time???
String abc = "Hello this is test";
String [] xyx = new String[abc.length()];
for ( i=0 ; i < abc.length() ; i++ ){
xyx[i] = abc.substring( i , i + 1 );
}

 
Angela Jessi
Ranch Hand
Posts: 428
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all,,
I am sorry actually i want to ask this
I want to parse following String
ABCDH2001API:0000:1:1:3:2:AB:3:ABC:4:ABCD
to
ABCDH2001API
0000
1
1
3
2
AB
3
ABC
4
ABCD
without using array and StringTokenizer. Only with the use of substring or startwith or other routines of the string.
Plz help me out,
Thanks
Angela
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angela,
Have you tried something like this?

Hope this helps.
Stephanie
[This message has been edited by Stephanie Grasson (edited February 27, 2001).]
 
Angela Jessi
Ranch Hand
Posts: 428
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Cindy and Stephanie,
I don't want to use Array? Plz help me out... ANd Sometime my message can be
String s = "ABCDH2001API:0000: :1:3:2:AB:3:ABC:4:ABCD";
So I can't count on del ":"
plz help me out..
Thanks
Angela

 
Stephanie Grasson
Ranch Hand
Posts: 347
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angela,
I am getting a little confused.
You say:

I don't want to use Array

but your original question said:

I want to store String into String Array called
String [] xyx = new String[abc.length()]
How can I do?

Maybe you could explain the question in more detail?
Thanks.
Stephanie
 
Angela Jessi
Ranch Hand
Posts: 428
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry Stephanie, it's my mistake , Plz don't go for first question(first post) i asked in wrong way.
Plz see second post I have asked....
You have sent me this example:
public static void main(String args[])
{
String s = "ABCDH2001API:0000:1:1:3:2:AB:3:ABC:4:ABCD";
// figure out how many substrings we have
int numColons = 0;
for(int i = 0; i < s.length(); i++)
{
if(s.charAt(i) == ':')
{
numColons++;
}
}
// create an array and parse
String afterParse[] = new String[(numColons + 1)];
int stop = s.indexOf(':');
int num = 0;
while(stop != -1)
{
afterParse[num] = s.substring(0, stop);
s = s.substring((stop + 1), s.length());
num++;
stop = s.indexOf(':');
}
afterParse[num] = s;
// print results
for(int j = 0; j < afterParse.length; j++)
{
System.out.println(afterParse[j]);
}
} }

It works fine.I don't want to use array here.
Thanks again,
Sorry for mistake
Angela
 
Elisabeth Van
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angela,
If I'm understanding your question correctly, you want to print the substrings without using an array.
If that is the case, can you just print out the substrings as you parse them instead of putting them into an array?
Replace afterParse[num] = s; with System.out.println(s);
Just a suggestion in case you were still working on this...couldn't quite tell if you'd gotten your question answered or not.
 
Angela Jessi
Ranch Hand
Posts: 428
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all,
I got the solution of my question without using String Tokenizer and array.
Angela
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic