splitting a string into a drop down

G

Guest

I have a string of dates seperated by commas and I need to seperate them and
put them into a dropdown control. With the code below I am able to only
remove the comma which results in one big long string with no spaces and the
string is listed 5 time. How can I seperate the dates into seperate strings.

Here is the code I have so far:

string strDelim = ",";
char[] charDelim = strDelim.ToCharArray();
string Dates = StartDate;
string[] splitDates = null;

for (int x = 1; x <= 5; x++)
{
splitDates = Dates.Split(charDelim, x);
foreach (string s in splitDates)
{
SelectDate.Items.Add(s);
}
}

Thanks, Justin.
 
K

Karl

Is this what you want?

string[] splitDates = StartDate.Split(',');
for (int i = 0 ; i < splitDates.Length; ++i){
SelectDate.Items.Add(splitDates);
}

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top