HoustonGuy
Programmer
I'm new to C# - so I'm having trouble iterating through a string using indexof.
My String: "Hello|There|How|Are|You|"
I'm trying to loop through each found instance of the pipe character: "|" to provide a resultset like this:
Hello
There
How
Are
You
Simple and frustrating. But here is the last test code I have:
I've tried many different versions- but I can't find the correct code to loop through each iteration.
Thanks from a C# newbie.
Also - any site that has great string manipulation samples? I've found a few - but they never seem to show looping or conditional examples.
My String: "Hello|There|How|Are|You|"
I'm trying to loop through each found instance of the pipe character: "|" to provide a resultset like this:
Hello
There
How
Are
You
Simple and frustrating. But here is the last test code I have:
Code:
string s = "Hello|There|How|Are|You|";
int sLength = s.LastIndexOf("|");
while (s.IndexOf("|") <= s.Length)
{
int startblock = s.IndexOf("|") + 1;
int endblock = s.IndexOf("|", startblock);
MessageBox.Show(s.Substring(startblock, endblock - startblock));
}
I've tried many different versions- but I can't find the correct code to loop through each iteration.
Thanks from a C# newbie.
Also - any site that has great string manipulation samples? I've found a few - but they never seem to show looping or conditional examples.