拆分字符串并存储到列表项中 [英] Split the String and stored into list item
本文介绍了拆分字符串并存储到列表项中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在名称变量中有一个像(Mohan,kumar,raja)这样的字符串值,我需要将这些名称拆分,并在列表框中显示...我该怎么做....我需要显示这个名字在列表框中逐个...?
I have a string value like ( Mohan,kumar,raja ) in name variable, I need to split that names without , and display that in a listbox...How can i do that.... i need to display that name one by one in a list box...?
推荐答案
你需要做这样的事情:
You need to do something like this :
List<String> items = new List<String>();
String name = "Mohan,kumar,raja";
String[] words = name.Split(',');
foreach (String word in words)
{
items.Add(word);
}
listBox1.DataSource = items;
试试这个代码
Try this code
string[] words = s.Split(',');
foreach (string word in words)
{
listbox.Items.Add(word);
}
尝试使用此。
string sample= "Mohan,kumar,raja";
string[] splitted=sample.Split(',');
string first=splitted[0];//this will be Mohan
string second=splitted[1];//this will be kumar
string third=splitted[2];//this will be raja
现在,只需将此添加到ListBox
如何:添加和清除项目在ListBox控件中 [ ^ ]
问候..:)
Now,simply add this to ListBox
How to: Add and Clear Items in a ListBox Control[^]
Regards..:)
这篇关于拆分字符串并存储到列表项中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文