我有一个逗号分隔的字符串。如何将其转换为换行符分隔格式。我的字符串如下所示:
red,yellow,green,orange,pink,black,white
并且需要以这种方式格式化:
red
yellow
green
orange
pink
black
white
这是我的代码:
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;
}