我似乎遇到了精神障碍,希望有人能指出我正确的方向。我有一个 csv 文件,它在值之间有许多逗号(随机),我有一些代码处理这个问题,它将两个逗号替换为一个等。看下面:
using (StreamReader r = new StreamReader(tbFilePathName.Text))
{
string AllLines;
string newLines;
//This skips the first line.
AllLines = r.ReadLine();
//Reads all the lines to the end.
AllLines = r.ReadToEnd();
//This replaces all the instances of a double comma into a single comma. Effectively getting all the data into one column of the csv.
newLines = Regex.Replace(AllLines, ",{2,}", ",").Trim(',');
rtbViewLines.AppendText(newLines);
r.Close();
但是我希望能够删除每行末尾的逗号,只在行内留下逗号。我怎样才能与下面的功能一起做到这一点?
newLines = Regex.Replace(AllLines, ",{2,}", ",").Trim(',');
谢谢!