C# 从字符串数组C创建CSV#
我想创建一个CSV,但是当一个值有逗号时,它的格式就错误了C# 从字符串数组C创建CSV#,c#,export-to-csv,comma,C#,Export To Csv,Comma,我想创建一个CSV,但是当一个值有逗号时,它的格式就错误了 List<string[]> output = new List<string[]>(); output.Add(valuesRow.ToArray()); int length = output.Count; for (int index = 0; index < length; index++) { stringBuilder.AppendLine(string.Join(delimiter,outp
List<string[]> output = new List<string[]>();
output.Add(valuesRow.ToArray());
int length = output.Count;
for (int index = 0; index < length; index++)
{
stringBuilder.AppendLine(string.Join(delimiter,output[index]));
}
列表输出=新列表();
Add(valuesRow.ToArray());
int length=output.Count;
for(int index=0;index
但是当输出[index]
的值带有逗号时,它的格式就错误了。更改
List<string[]> output = new List<string[]>();
output.Add(valuesRow.ToArray());
int length = output.Count;
for (int index = 0; index < length; index++)
{
stringBuilder.AppendLine(string.Join(delimiter,output[index]));
}
stringBuilder.AppendLine(string.Join(delimiter,output[index]));
到
改变
stringBuilder.AppendLine(string.Join(delimiter,output[index]));
到
您可以使用CsvHelper生成.csv输出。您可以指定列并按字段名插入值
您可以使用CsvHelper生成.csv输出。您可以指定列并按字段名插入值
你能从
输出[index]
中删除逗号吗?你能从输出[index]
中删除逗号吗?当然,下一个问题是处理双引号字符的字段。@JoelCoehoorn当然:)x.Replace(“\”,“\”\”);
当然,下一个问题是处理双引号字符的字段。@JoelCoehoorn当然:)x.Replace(“\”,“\”)代码>