Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

loop through delimited values in string

Thread view: 
JR - 22 Jun 2007 04:39 GMT
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
bencoe@gmail.com - 22 Jun 2007 05:27 GMT
> I have a string with a bunch of values separated by a tilde and
> greater than sign.  So like.
[quoted text clipped - 19 lines]
>
> JR

String values[]=myList.split("->");
for(int i=0;i<values.length;i++)
 System.out.println(values[i]);
hiwa - 22 Jun 2007 05:49 GMT
> I have a string with a bunch of values separated by a tilde and
> greater than sign.  So like.
[quoted text clipped - 19 lines]
>
> JR

Use String.split() method.
JR - 23 Jun 2007 03:02 GMT
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

> > I have a string with a bunch of values separated by a tilde and
> > greater than sign.  So like.
[quoted text clipped - 23 lines]
>
> - Show quoted text -
JR - 23 Jun 2007 03:04 GMT
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
[quoted text clipped - 35 lines]
>
> - Show quoted text -
Lew - 23 Jun 2007 13:58 GMT
> Got it, need to prefix the pipe with \\

And to post replies inline with quoted text instead of top posting.

Signature

Lew

Roedy Green - 22 Jun 2007 06:20 GMT
>"123~>abv~>asdflkjasfdlkjslkdfjj~>asdflkj~>sldfkjsdlfkjadfs";


see Regex split  http://mindprod.com/jgloss/regex.html

The string version of split will reparse and recompile the regex on
every use.

the following chars are reserved in Regex and need to be quoted:
$ ( ) * + - . < = ? [ \ ] ^ { | }
See http://mindprod.com/applets/quoter.html 

You luck out in this case. Neither of ~> needs quoting.

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.