[英]How can i parse specific char/letter from string and add it to a List<string>?
txtDir is a textBox if I itype inside only hello then in test1 should be only once the word hello But if i type in the textBox hello1/hello2/hello3 Then in test1 i should see txtDir是一个textBox,如果我只在hello中键入内容,那么在test1中应该只是一次单词hello。但是,如果我在textBox中键入hello1 / hello2 / hello3,则在test1中我应该看到
hello1 hello2 hello3 hello1 hello2 hello3
List<string> test1 = new List<string>();
int index = 0;
while(true)
{
index = txtDir.Text.IndexOf("/");
string text = txtDir.Text.Substring(0, index);
test1.Add(text);
newNodeParsed = new TreeNode(text);
rootNode.Nodes.Add(newNodeParsed);
}
How can I parse and get the text between each '/' and add it to the List ? 我如何解析并获取每个'/'之间的文本并将其添加到列表中?
将输入字符串拆分为字符串字段的字符串数组,并将该数组转换为列表:
List<string> test1 = txtDir.Text.Split('/').ToList();
Assuming that you want to insert the values on the test1 for each word in your textBox splited by '/' character you should do it: 假设您要在test1上为textBox中的每个单词插入值(用'/'字符分隔),您应该这样做:
List<String> test1 = new List<String>();
test1.AddRange(txtDir.Text.Split('/'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.