Click here to Skip to main content
12,764,177 members (37,909 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0 ASP.NET4
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 3-Sep-13 20:50pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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)
listBox1.DataSource = items;
S.Mohankumar 4-Sep-13 2:20am
Thank you!
ridoy 4-Sep-13 2:23am
Glad to help you,:)
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Try this code

string[] words = s.Split(',');
    foreach (string word in words)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try to use this.
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[^]

ridoy 4-Sep-13 2:08am
possibly it would be sample.Split() rather than splite()!
Rohan Leuva 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 4 Sep 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100