2012-05-09 13 views
0

を解析するために、私は私は私がしている結果となります私自身のコードを書くベストC#のファイルクラステキストファイル

Index: D:/QATV2Demo/Main.msbuild 
=================================================================== 
--- D:/QATV2Demo/Main.msbuild (revision 12414) 
+++ D:/QATV2Demo/Main.msbuild (revision 12416) 
--- D:/QATV2Demo/Main.msbuild (revision 12414) 
+++ D:/QATV2Demo/Main.msbuild (revision 12416) 
@@ -39,7 +39,7 @@ 
    AssemblyFile="$(ToolsBinPath)\MSBuild.Community.Tasks.dll" /> 

- <FxCop_CriticalErrors>10</FxCop_CriticalErrors> 
+ <FxCop_CriticalErrors>0</FxCop_CriticalErrors> 


<FxCop_Errors>0</FxCop_Errors> 
<FxCop_CriticalWarnings>0</FxCop_CriticalWarnings> 
<FxCop_Warnings>0</FxCop_Warnings> 


    Index: D:/QATV2Demo/QATV2Demo/QATConstant.cs 
=================================================================== 
--- D:/QATV2Demo/QATV2Demo/QATConstant.cs (revision 12414) 
+++ D:/QATV2Demo/QATV2Demo/QATConstant.cs (revision 12416) 
@@ -9,7 +9,7 @@ 
    { 
    public static readonly string PAGE_DATA_DROP_DOWN_MODE = "D"; 
    public static readonly string PAGE_DATA_GRID_MODE = "G"; 
-  public static readonly string REPORT = "Report"; 
+  public static readonly string REPORT = "Report1"; 
    public static readonly string ITEM_COUNT = "ItemCount"; 
} 

}

今私のファイル内のテキストを持って、次のしています行の先頭は - と+ で、ファイルの内容の違いを示しています。

は、ここに私のコード

int counter = 0; 
     string line; 
     string filename = args[0].ToString(); 


     using (System.IO.StreamReader file = new StreamReader(filename)) 
     { 
      while ((line = file.ReadLine()) != null) 
      { 
       if (line.StartsWith("- ")||line.StartsWith("+ ")) 
       { 
        Console.WriteLine(line.Trim('-',' ','+')); 

       } 
       counter++; 
      } 

      file.Close(); 
     } 
     // Suspend the screen. 
     Console.WriteLine(counter); 

これは私が使用しているラフコードです。

はネットクラスは

事前のおかげで、このシナリオでは私のために最善であるドットを教えてください。

答えて

1

コードがあなたの望むことを実行すれば、解析を変更する必要はありません。あなたはこのように、File.ReadLinesを使用して、ファイルの読み取りを簡素化することができます:あなたがそれらを見つけた後、それ以外は

foreach (var line in File.ReadLines(filename)) 
{ 
    if (line.StartsWith("- ") || line.StartsWith("+ ")) 
    { 
     // do stuff here 
    } 
    ++counter; 
} 

、あなたが追加され、削除された行で何をしたいのか言っていません。だから私はそこに何か勧告を出すことはできない。

+0

私はちょうどその場所で良いかもしれない他のクラスがあることを明確にしたいと思います。このコンテンツをXMLファイル( 10)に書き込むにはどうすればよいですか? –

関連する問題