从CSV数据中删除尾随逗号 [英] Removing trailing comma from CSV data
本文介绍了从CSV数据中删除尾随逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是用于在另一个数字之后添加逗号的代码,但我要删除最后一个逗号:
This is the Code for adding comma after another number, but I want to delete the last comma:
str_MSISDN.Append("'" + _MSISDN[x].TrimStart() + "'" + ",");
推荐答案
code> String.Join ,它将正确开始。您可以使用LINQ来修改值。例如:
Instead of manually appending things, I suggest you use String.Join
which will get it right to start with. You can use LINQ to do the trimming of the values. For example:
string x = string.Join(",", _MSISDN.Select(x => "'" + x.TrimStart() + "'")
.ToArray());
编辑:更好的版本可以使用 MoreLINQ 及其 ToDelimitedString
方法:
A nicer version of this is available with MoreLINQ and its ToDelimitedString
method:
string x = _MSISDN.Select(x => "'" + x.TrimStart() + "'")
.ToDelimitedString(",");
这篇关于从CSV数据中删除尾随逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文