【发布时间】:2014-12-25 17:50:31
【问题描述】:
我想从下面的文本文件中删除双引号。我需要使用我的 C# 应用程序输入文件并读取文本文件,然后删除所有双引号并给出输出。 我需要删除所有引号并将它们变成完美的四行距格式 那么我该怎么做呢。
输入文件
Designator Comment Footprint Center-X(mm) Center-Y(mm)
"C5" "CAP,1n,50V.0603" "CAPC1608N" "97.733" "73.025"
"C4" "CAP,1n,50V.0603" "CAPC1608N" "99.638" "73.025"
"C3" "CAP,1n,50V.0603" "CAPC1608N" "101.543" "73.025"
"C7" "CAP1233,,1n,50V.0603" "CAPC1608N" "103.448" "73.025"
"C8" "CAP1233,1n,50V.0603" "CAPC1608N" "105.353" "73.025"
"C9" "CAP455,1n,50V.0603" "CAPC1608N" "107.258" "73.025"
"C10" "CAP4522,1n,50V.0603" "CAPC1608N" "109.163" "73.025"
我的 C# 应用程序中用于输入文本文件的代码:
private void convert_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = @"C:\files";
ofd.Filter = "TXT files (*.txt)|*.txt";
ofd.FilterIndex = 2;
ofd.RestoreDirectory = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
int[] cols = new int[] { 15, 30, 15, 20, 12 };
string[] strLines = System.IO.File.ReadAllLines(fileName);
StringBuilder sb = new StringBuilder();
string line = string.Empty;
for (int i = 0; i < strLines.Length; i++)
{
line = RemoveWhiteSpace(strLines[i]).Trim(); // here i am getting error in RemoveWhiteSpace, that it is not in the context
string[] cells = line.Replace("\"", "").Split(new string[] { " " }, StringSplitOptions.None);
for (int c = 0; c < cells.Length; c++)
sb.Append(cells[c].PadRight(cols[c]));
sb.Append("\r\n");
}
//System.IO.File.WriteAllText(fileName, sb.ToString());
MessageBox.Show(sb.ToString());
}
}
我该怎么做?请帮帮我。
我想为我输入的所有文本文件获取以下样式的格式。所以对于上面的文本文件,我想得到如下所示的格式
Designator Comment Footprint Center-X(mm) Center-Y(mm)
C5 CAP,1n,50V.0603 CAPC1608N 97.733 73.025
C4 CAP,1n,50V.0603 CAPC1608N 99.638 73.025
C3 CAP,1n,50V.0603 CAPC1608N 101.543 73.025
C7 CAP,1n,50V.0603 CAPC1608N 103.448 73.025
C8 CAP,1n,50V.0603 CAPC1608N 105.353 73.025
C9 CAP,1n,50V.0603 CAPC1608N 107.258 73.025
C10 CAP,1n,50V.0603 CAPC1608N 109.163 73.025
【问题讨论】:
标签: c# winforms double-quotes file-conversion