Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

hey guys

If  I have a text box that contains a load of text what code could I use to

1. Split text when the text contains "&"

2. Add to a list box

 

e.g. 

TextBox1.Text = "name=bob&age=23&sex=male";

Listbox1:

name=bob

age=23

sex=male

 

Thanks

 

UPDATE: Thanks for answer, this is my final code  if anyone else is interested

[CODE]

            string text = richTextBox1.Text;
            string[] words = text.Split('&');

            foreach (string word in words)
            {
                listBox1.Items.Add(word);
            }

[/CODE]

Posted
Updated 24-Nov-09 6:10am
v2

1 solution

Well, you answered your own question.  The string class has a split method.  You can turn this into an array of strings, each containing the values you want.  You can even make that array the data source of the listbox, which will cause it to show as you want.

 
Share this answer
 

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