J'ai une chaîne de caractères séparée par des virgules. Comment puis-je la convertir en format séparé par un saut de ligne ? Ma chaîne ressemble à ceci :
red,yellow,green,orange,pink,black,white
Et doit être formaté de cette façon :
red
yellow
green
orange
pink
black
white
Voici mon code :
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(s);
}
}
string res = string.Join(", ", colours);
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"F:\test.txt", true))
{
file.WriteLine(res);
}
return res;
}