我有几个List<string>
,格式如下:
List 1 List 2 List 3
1 A One
2 B Two
3 C Three
4 D Four
5 E Five
所以在代码形式中,它就像:
List<string> list1 = {"1","2","3","4","5"};
List<string> list2 = {"A","B","C","D","E"};
List<string> list3 = {"One","Two","Three","Four","Five"};
我的问题是:
list1,list2,list3 1,A,one 2,b,two 3,c,three 4,d,four 5,e,five
,
附加到每个index
的末尾,还是在多维列表中将分隔符作为自己的索引?答案 0 :(得分:0)
如果性能是您的主要考虑因素,我会使用现有的csv库来处理您的语言,因为它可能已经过很好的优化。
如果这是一个太多的开销,而你只是想要一个简单的函数,我在我的一些代码中使用相同的概念。我使用语言的join/implode
函数创建逗号分隔字符串列表,然后使用join
列出\n
。
我习惯用动态语言来做这件事,但你可以在下面的伪代码示例中看到这个概念:
header = {"List1", "List2", "List3"}
list1 = {"1","2","3","4","5"};
list2 = {"A","B","C","D","E"};
list3 = {"One","Two","Three","Four","Five"};
values = {header, list1, list2, list3};
for index in values
values[index] = values[index].join(",");
values = values.join("\n");