loop through delimited values in string

J

JR

I have a string with a bunch of values separated by a tilde and
greater than sign. So like.

String myList =
"123~>abv~>asdflkjasfdlkjslkdfjj~>asdflkj~>sldfkjsdlfkjadfs";

For simplicity sake to get me started, can someone share some code on
how I would loop through the myList values and output it to the screen
in the following format:

123
abv
asdflkjasfdlkjslkdfjj
asdflkj
sldfkjsdlfkjadfs


If there is a way to do this other than a loop I would prefer it be
looping through as I need to do some other stuff to each value as it
parses threw it.

Thanks.

JR
 
B

bencoe

I have a string with a bunch of values separated by a tilde and
greater than sign. So like.

String myList =
"123~>abv~>asdflkjasfdlkjslkdfjj~>asdflkj~>sldfkjsdlfkjadfs";

For simplicity sake to get me started, can someone share some code on
how I would loop through the myList values and output it to the screen
in the following format:

123
abv
asdflkjasfdlkjslkdfjj
asdflkj
sldfkjsdlfkjadfs

If there is a way to do this other than a loop I would prefer it be
looping through as I need to do some other stuff to each value as it
parses threw it.

Thanks.

JR

String values[]=myList.split("->");
for(int i=0;i<values.length;i++)
System.out.println(values);
 
H

hiwa

I have a string with a bunch of values separated by a tilde and
greater than sign. So like.

String myList =
"123~>abv~>asdflkjasfdlkjslkdfjj~>asdflkj~>sldfkjsdlfkjadfs";

For simplicity sake to get me started, can someone share some code on
how I would loop through the myList values and output it to the screen
in the following format:

123
abv
asdflkjasfdlkjslkdfjj
asdflkj
sldfkjsdlfkjadfs

If there is a way to do this other than a loop I would prefer it be
looping through as I need to do some other stuff to each value as it
parses threw it.

Thanks.

JR

Use String.split() method.
 
J

JR

Thank you everyone for you input. Very helpful and much appreciated.
One note though, I am not so lucky as was mentioned. I do have a pipe
character in one of my situations it's "|~" without the quotes. Tried
using new char[] { '|' } from the Quoter site but could figure out how
to formulate: split("|~")

Thanks.

JR
 
J

JR

Got it, need to prefix the pipe with \\

Thanks again.

Thank you everyone for you input. Very helpful and much appreciated.
One note though, I am not so lucky as was mentioned. I do have a pipe
character in one of my situations it's "|~" without the quotes. Tried
using new char[] { '|' } from the Quoter site but could figure out how
to formulate: split("|~")

Thanks.

JR
Use String.split() method.- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top