Click here to Skip to main content
15,918,624 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I retrieve text from every two words from large string into array.
for example:

blablabla

first

blablabla

second

blablablablablabla

third

blablablablablabla



the output i want to get:
str[0]="first"
str[1]="second"
str[2]="third"

?
Posted
Updated 21-Sep-11 21:47pm
v2
Comments
Dalek Dave 22-Sep-11 3:48am    
Edited for Readability and Grammar.

1 solution

You can create an array from the string using a delimiter either comma(,) or blank space and then use a loop to iterate through them and print the elements skipping every second item from the array:

C#
String[] MyArray= SampleString.Split(',');
for (i=0;i<=MyArray.Length ,i=i+2)
{
Console.WritleLine(MyArray[i].ToString());
}
 
Share this answer
 
Comments
Dalek Dave 22-Sep-11 3:48am    
Spot on!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900