我想從我的下面的文本文件中刪除雙引號。我需要使用我的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
來吧我不知道現在如何給我的代碼.. – 2014-10-30 14:24:54
請參閱我的編輯代碼 – 2014-10-30 14:25:56
這裏我在RemoveWhiteSpace中收到錯誤,它不是在上下文 – 2014-10-30 14:27:12