The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.



Posted by Clint on August 02, 2001 at 12:49 PM

> > how would one go about parsing a string and breaking it up based on a delimiter, and add them as elements of an array... say, we have
> > String parent = "something1; something2; something3";

> > I can go about using a while loop to get each one
> > int begin = 0;
> > int index1 = parent.indexOf(";");
> > while (parent.charAt(index1) != -1){
> > String element1 = parent.substring(begin,index1);

> > and something along those lines. however would i get all the elements from the parent string? and how would I add all these substring elements to a new String array? Or is there a better way of doing this?

> > any help/insight would be appreciated. thanx much
> > Clint

> use the StringTokenizer class additionally it might help to manipulate strings using the StringBuffer class, another interesting class is StringCharacterIterator. Let me know if the above helped.

that helped. Thank you for the help. I'm just learning Java, hence the difficulty in thinking.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us