Click here to Skip to main content
15,906,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...?
Posted

You need to do something like this :
C#
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;
 
Share this answer
 
v3
Comments
SnvMohan 4-Sep-13 2:20am    
Thank you!
ridoy 4-Sep-13 2:23am    
Glad to help you,:)
Try this code

C#
string[] words = s.Split(',');
    foreach (string word in words)
    {
        listbox.Items.Add(word);
    }
 
Share this answer
 
Try to use this.
C#
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

Now,simply add this to ListBox

How to: Add and Clear Items in a ListBox Control[^]

Regards..:)
 
Share this answer
 
v2
Comments
ridoy 4-Sep-13 2:08am    
possibly it would be sample.Split() rather than splite()!
Thanks7872 4-Sep-13 2:13am    
Typo.My bad.Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900