The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2001

Advertisement

Advertisement

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.

Message:

substring a string and add it as an element of a String array

Posted by Clint on August 01, 2001 at 8:55 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



Replies:

Sponsored Links



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