0

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?

1
  • 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! Commented Jul 12, 2013 at 14:40

6 Answers 6

3
string str = "Hello Word Hello" ;
var strarray = str.Split(' ') ;

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

Sign up to request clarification or add additional context in comments.

1 Comment

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
3

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
}

2 Comments

Did you downvote him for using the same variable names in a one-liner piece of throwaway example code??
@SirajMansour No one has ownership of any code and I can't see that you wrote my code.
1

If they are seperated by spaces :

var MyArray = MyTextBox.Text.Split(' ');

Comments

0

There's a very simple way of doing this:

string text = "some text sample";
List<string> ltext = text.Split(' ').ToList();

Comments

0

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

Comments

0

use .Split() method like this:

var array = textboxText.Split(' ');

3 Comments

@Alexy the split function returns a string[] no need for the .ToArray() in the end
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[].
@SirajMansour I agree with you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.