向List添加新值仍然是以前值的一部分

时间:2018-04-13 18:25:54

标签: c# list split

我从url获得了以下形式的字符串:

450,2277,687005562
13331,99,21042886
8023,99,21054328

当我尝试将值添加到这样的列表中时:

List<string> splitted = new List<string>();
string fileList = results;
string[] tempStr;
tempStr = fileList.Split(new Char[] {'\n',','});
int j = 0;
foreach (string item in tempStr)
{
    if (!string.IsNullOrWhiteSpace(item))
    {
        splitted.Add(item);
        Console.Write(splitted[j]);
        Console.ReadKey();
        j++;
    }
}

我获得的结果是:

450,2277,687005562,然后是133315562,它是13331和前一个数字的最后一位数的组合,因为它更长。

如何将每个值添加到其单元格中?

谢谢。

1 个答案:

答案 0 :(得分:1)

这是因为您使用的是Write()而不是WriteLine()

试试这个。

List<string> splitted = new List<string>();
string fileList = results;
string[] tempStr;

tempStr = fileList.Split(new Char[] {'\n',','});
int j = 0;
foreach (string item in tempStr)
{
    if (!string.IsNullOrWhiteSpace(item))
    {
        splitted.Add(item);
        Console.WriteLine(splitted[j]);
        Console.ReadKey();
        j++;
    }
}
相关问题