A
Asad Kazmi
Hi,
I am extracting my String (mytext) but it only repitedly displays "My" 6
times. While I want to extract all character on new line one by one.Like,
My
Name
Is
Asad
Raza
Kazmi
So can some one tell me where is the problem ?
Regards
Asad Kazmi
******************************************
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=mytext.substring(index);
else
substr=mytext.substring(index,endindex);
}
index=endindex + 1;
// Display the Substring
for(int i=0; i < substr.length; i++)
System.out.println(substr);
}
}
I am extracting my String (mytext) but it only repitedly displays "My" 6
times. While I want to extract all character on new line one by one.Like,
My
Name
Is
Asad
Raza
Kazmi
So can some one tell me where is the problem ?
Regards
Asad Kazmi
******************************************
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=mytext.substring(index);
else
substr=mytext.substring(index,endindex);
}
index=endindex + 1;
// Display the Substring
for(int i=0; i < substr.length; i++)
System.out.println(substr);
}
}