Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Array Question

Reply
Thread Tools

Array Question

 
 
Roedy Green
Guest
Posts: n/a
 
      06-29-2004
On Mon, 28 Jun 2004 22:42:27 +0500, "Asad Kazmi" <(E-Mail Removed)>
wrote or quoted :

>you ammended this part and put index=endindex+1 inside closing braces while
>i put this statement out of braces. so i was refering this as your code.
>
>Regards
>Asad


I see the problem. Superdude made that mod, not me.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Superdude
Guest
Posts: n/a
 
      06-30-2004
Yep,

public static void main(String[] args) {
String mytext="My Name is Asad Raza Kazmi";

int count=0;
int index=0;
char seperator=' '; //Determines the no of substrings
do {
++count;
++index;
index=mytext.indexOf(seperator,index);
}
while(index != -1);
// Extract the substring into an array

String[] substr = new String[count]; // Allocate for Substring
index=0; // Substring Start index
int endindex = 0; // Substring endindex
for(int i=0; i<count; i++) {
endindex=mytext.indexOf(seperator,index); //Find next
//seperator
if(endindex == -1)
substr[i]=mytext.substring(index);
else
substr[i]=mytext.substring(index,endindex);
index=endindex + 1;
}


// Display the Substring
for(int i=0; i < substr.length; i++)
System.out.println(substr[i]);
}


Worked fine.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Question concerning array.array and C++ Fabio Python 0 11-05-2008 03:53 PM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
"array of Derived" is not a kind-of "array of Base" question Joseph Turian C++ 11 01-19-2005 11:53 AM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM



Advertisments