Reputation: 73
Can anyone help with a little code i want to make array which first index will have first word of textbox text:
array[0] first word of text array[1] second word of text
can anyone help me?
Upvotes: 0
Views: 15670
Reputation: 5398
use .Split() method like this:
var array = textboxText.Split(' ');
Upvotes: 0
Reputation: 13003
Use the Split
method of the string type.
It will split your string by a character specification to a string array (string[]
).
For example:
textBox1.Text = "The world is full of fools";
string[] words = textBox1.Text.Split(' ');
foreach(string word in words)
{
//iterate your words here
}
Upvotes: 3
Reputation: 4542
U can use the split method,it gets a string array back,you need to pass a char array with the characters to split upon:
string[] str = textBox1.Text.Split(new char[] { ' ', ',', ':', ';', '.' });
Upvotes: 0
Reputation: 348
There's a very simple way of doing this:
string text = "some text sample";
List<string> ltext = text.Split(' ').ToList();
Upvotes: 0
Reputation: 3364
string str = "Hello Word Hello" ;
var strarray = str.Split(' ') ;
You can replace the str with TextBox.Text...
Upvotes: 3
Reputation: 2602
If they are seperated by spaces :
var MyArray = MyTextBox.Text.Split(' ');
Upvotes: 1