Mohammad Mahdi
Mohammad Mahdi

Reputation: 187

Separate words in the textbox C#

I want to write a text like this in the text box: "Sentence1::Sentence2::Sentence3" and Then separate it to three parts and put them in three separately strings. I used string.split method but I couldn't put them to strings.

string authors = "Sentence1::Sentence2::Sentence3";
string[] authorsList = authors.Split("::");

Upvotes: 0

Views: 528

Answers (1)

Idle_Mind
Idle_Mind

Reputation: 39152

You have an ARRAY of Strings after the Split(). You access the strings by index. Here's an example:

string authors = "Sentence1::Sentence2::Sentence3";
string[] authorsList = authors.Split("::");

for(int i=0; i<authorsList.Length; i++) {
  Console.WriteLine(i + ": " + authorsList[i]);
}

Output:

0: Sentence1
1: Sentence2
2: Sentence3

Upvotes: 2

Related Questions