在文本框中分隔单词 C#
Separate words in the textbox C#
我想在文本框中写这样一段文字:“Sentence1::Sentence2::Sentence3”,然后把它分成三部分,分别放在三个单独的字符串中。我使用了 string.split 方法,但无法将它们放入字符串中。
string authors = "Sentence1::Sentence2::Sentence3";
string[] authorsList = authors.Split("::");
您在 Split() 之后有一个字符串数组。您可以按索引访问字符串。这是一个例子:
string authors = "Sentence1::Sentence2::Sentence3";
string[] authorsList = authors.Split("::");
for(int i=0; i<authorsList.Length; i++) {
Console.WriteLine(i + ": " + authorsList[i]);
}
输出:
0: Sentence1
1: Sentence2
2: Sentence3
我想在文本框中写这样一段文字:“Sentence1::Sentence2::Sentence3”,然后把它分成三部分,分别放在三个单独的字符串中。我使用了 string.split 方法,但无法将它们放入字符串中。
string authors = "Sentence1::Sentence2::Sentence3";
string[] authorsList = authors.Split("::");
您在 Split() 之后有一个字符串数组。您可以按索引访问字符串。这是一个例子:
string authors = "Sentence1::Sentence2::Sentence3";
string[] authorsList = authors.Split("::");
for(int i=0; i<authorsList.Length; i++) {
Console.WriteLine(i + ": " + authorsList[i]);
}
输出:
0: Sentence1
1: Sentence2
2: Sentence3