0

我有一个字符串被读入,然后输出到一个里面有逗号的 CSV 文件。字符串是

美国,黑白 1-25

我想要的只是让该字符串留在一个特定的单元格中,而不是分成两个不同的单元格。对此可能有一个简单的答案,但我无法做到这一点。任何帮助将非常感激。如果需要有人想看一下,这是我的输出代码...

    public void printAll()
    {
        output2.WriteLine("All companies in order of sequence number, THIS IS OUTPUT 2!");
        output2.WriteLine("___________________________________________________________________________________________");
        int i = listHead2;

        //Loops until the end of the list, printing out info
        while (i != -1)
        {
            output2.WriteLine("{0}" + ", {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}, {33}, {34}, {35}",
                leaseName2[i], fieldName2[i],reservoir2[i], operator2[i], county2[i], state2[i],  majo2[i], resvCatgory2[i], disRate2[i], netOil2Int2[i], netGas2Int2[i], workingInt2[i], grossWells2[i]
                ,ultOil2[i], ultGas2[i], grossOil2[i], grossNGL2[i], grossGas2[i], netOil2[i], netGas2[i], netNGL2[i], revToInt2[i], operExpense2[i], totInvest2[i], revOil2[i], revGas2[i], operatingProfit2[i],
            revNGL2[i], discNetIncome2[i], seqNum2[i], wellID2[i], incASN2[i], lifeYears2[i],  ownQual2[i], prodTax2[i], AdValorem2Tax2[i]);
            i = pointers2[i];
        }
    }

谢谢。

4

3 回答 3

3

You could try enclosing the field in double quotes: "USA, B&W 1-25" That should cause the string to be considered as one column.

于 2013-05-31T15:42:46.530 回答
3

您可以创建一个引用字符串的小方法:

public string QuoteString(string input)
{
    return "\"" + input.Replace("\"", "\"\"") + "\"";
}

然后你可以这样使用:

QuoteString(leaseName2[i]), QuoteString(fieldName2[i]),...

祝你的代码好运。

于 2013-05-31T15:48:54.490 回答
0

CSV files don't necessarily need to be comma separated. You could use semicolon for separating if that helps!

于 2013-05-31T15:44:32.070 回答