我有一个问题,如何拆分字符串并逐行显示拆分字符串?
字符串:
What is "that" ENUM "No", "Yes", "OK", "Cancel";
我想拥有DataTable:
Name Type Comment
"that" ENUM "No" // all of them
"Yes" // should be
"OK" // in the same
"Cancel" // cell
必须是string[] tmpList = tmp.Split(new Char[] { ' ',',', ';' }, StringSplitOptions.RemoveEmptyEntries);
然后是attributeDEF.Rows.Add(new object[] { tmpList1[1], tmpList1[2], tmpList1[3] + "\n" + tmpList[a]+ "\n"});
有人能给我一些线索吗?
答案 0 :(得分:1)
以下代码将为您生成一行:
string tmp = @"What is ""that"" ENUM ""No"", ""Yes"", ""OK"", ""Cancel";
string[] tmpList = tmp.Split(new Char[] { ' ',',', ';' }, StringSplitOptions.RemoveEmptyEntries);
var row = new object[] { tmpList[0], tmpList[3], string.Join("\n", tmpList.Skip(4).ToArray()) };
答案 1 :(得分:1)
如果您要求加入最后一个单元格的字符串,那么这可能是一个选项:
var result = String.Join("\n", tmpList.Skip(4).ToArray());