Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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?

share|improve this question
6  
Have you tried anything on this? I could write the function for you, but I don't think that would really help you. Help us help you! – Tim Jul 12 '13 at 14:40
string str = "Hello Word Hello" ;
var strarray = str.Split(' ') ;

You can replace the str with TextBox.Text...

share|improve this answer
    
thanks guys now how i can see result on label? i mean i have 2 labels and i want to make next: on first label text i want to type first word on second label second word – user2576809 Jul 12 '13 at 15:09

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
}
share|improve this answer
1  
Did you downvote him for using the same variable names in a one-liner piece of throwaway example code?? – Tim Jul 12 '13 at 14:46
    
@SirajMansour No one has ownership of any code and I can't see that you wrote my code. – Yair Nevet Jul 12 '13 at 14:50

If they are seperated by spaces :

var MyArray = MyTextBox.Text.Split(' ');
share|improve this answer

There's a very simple way of doing this:

string text = "some text sample";
List<string> ltext = text.Split(' ').ToList();
share|improve this answer

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[] { ' ', ',', ':', ';', '.' });
share|improve this answer

use .Split() method like this:

var array = textboxText.Split(' ');
share|improve this answer
    
He asked for an array :) – Siraj Mansour Jul 12 '13 at 14:43
    
@Alexy the split function returns a string[] no need for the .ToArray() in the end – Siraj Mansour Jul 12 '13 at 14:50
    
and no need for var either :) --best practices:if you know you need an int just declare an int as if you know you need(or that you will get and string[])just declare string[]. – terrybozzio Jul 12 '13 at 14:59
1  
@SirajMansour I agree with you – Oleksii Aza Jul 12 '13 at 15:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.