次の C# コードを使用して、テキスト ファイルに出力しようとしています。問題は、出力された情報の最後にカンマがあり、後でファイルを使用するプログラムでは機能しないことです。このカンマを取り除く方法を見つけようとしています...
var toFile = Path.Combine(GetTextPath(),
string.Format(heatname + "_{0}.txt", DateTime.Now.ToString("yyyyMMdd")));
string ElementsNum = RoundedValues.Count.ToString();
DateTime dt = System.DateTime.Now;
var year = dt.ToString("yy");
var month = dt.ToString("MM");
var day = dt.ToString("dd");
var minute = dt.ToString("mm");
using (var fs = File.OpenWrite(toFile))
using (TextWriter sw = new StreamWriter(fs))
{
sw.Write("NA" + "," + dt.Hour.ToString() + "," + minute + "," + day + ","
+ month + "," + year + "," + "ALTEST " + "," +
"ALTEST " + "," + heatgrade + " " + "," + " " + "," + heatname + "," +
DT2.Rows[0][3].ToString() + "," + heatgrade + "," + "OE2" + "," + "," +
"," + "," + "," + "," + "," + " " + ElementsNum);
foreach (var pair in RoundedValues.Zip(Elements, (a, b) => new { A = a, B = b }))
{
sw.Write(pair.B.ToString() + ", " + pair.A.ToString() + ",");
}
}