Just use Split
:
string[] yourStrings = s.Split(',');
Actually, what I think you’re asking for is a return string like this:
"red, blue, green, yellow"
To achieve that, you need to use string.Join
. Try this:
public static string getcolours()
{
List<string> colours = new List<string>();
DBClass db = new DBClass();
DataTable allcolours = new DataTable();
allcolours = db.GetTableSP("kt_getcolors");
for (int i = 0; i < allcolours.Rows.Count; i++)
{
string s = allcolours.Rows[i].ItemArray[0].ToString();
string missingpath = "images/color/" + s + ".jpg";
if (!FileExists(missingpath))
{
colours.Add(missingpath);
}
}
return string.Join(", ", colours);
}
7
solved String Split with comma [duplicate]