![](/img/trans.png)
[英]How can I concatenate all the column values in a row, and then concatenate all rows in a DataTable into a single string?
[英]how to concatenate all rows of a column into a single field Using C#
此解決方案適用於 SSIS。
完成后,您將在需要刪除的變量上多出一個“,”。
使用表達式。
concat = left(concat, len(concat)-1)
你說的都是c#。 這是通過 Core 5 完成的。
var yourData = File.ReadAllLines("yourFile.csv")
.Skip(1)
.Select(x => x.Split(','))
.Select(x => new
{
Name = x[0] //only working with Name column
,Type = int.Parse(x[1]) //Only added for reference for handling more columns
});
string namesJoined = string.Join(',', yourData.Select(x => x.Name));
這是非常基本的代碼,並沒有處理可能在 csv 中的瘋狂事情,例如名稱中的逗號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.