2017-01-22 10 views
0

に新しい行を追加します。検索と私はこのようなコード持っているC#の

reset <= '1'; 
ds <= '0'; 
wait for 20ns; 
wait until clk = '0'; 
reset <= '0'; 
wait until clk = '1'; 
wait until clk = '0'; 
inexp <= x"00903ad9"; 
inmod <= x"03b2c159"; 
report "clock init"; 
indata <= x"72624326"; 
wait until clk = '1'; 
wait for 2ns; 
ds <= '1'; 
wait until ready = '0'; 
ds <= '0'; 
wait until ready = '1'; 
wait for 500ns; 
reset <= '1'; 
ds <= '0'; 
wait for 20ns; 
wait until clk = '0'; 
reset <= '0'; 

を、私はそれぞれの行で"<="を検索し、この行の前に追加する新しい行を追加する(ファイルに書き込む) 私が見つけます私のコードでこの単語が、しかし、追加のために考えていない!あなたの新しいファイルを作成し、すべてを書き、このコードでは

System.IO.StreamReader file = new System.IO.StreamReader("e:\\file.txt"); 
System.IO.StreamWriter resultFile = new System.IO.StreamWriter("e:\\resultFile.txt", false); 
while ((line = file.ReadLine()) != null) 
{ 
    if (line.Contains("<=")) 
    { 
     resultFile.WriteLine(Environment.NewLine + counter.ToString() + ": " + line);      
    } 

    // if you don't want to write lines without "<=" - delete "else" block 
    else 
    { 
     resultFile.WriteLine(counter.ToString() + ": " + line);  
    } 
    counter++; 
} 

:新しいテキストがにあなたのコードを変更ファイルに書き込む

int counter = 1; 
    string line; 

    System.IO.StreamReader file = new System.IO.StreamReader("e:\\file.txt"); 
    while ((line = file.ReadLine()) != null) 
    { 
     if (line.Contains("<=")) 
     { 
      Console.WriteLine(counter.ToString() + ": " + line);      
     } 
     counter++; 
    } 

    file.Close(); 

おかげ

答えて

2

を: 見つけると、このコードで行を与え得ますfile.txtからそれにライン。行に<=が含まれている場合、最初に改行を追加します。

したがって、ディスクEには、必要なテキストを含む新しいファイルresultFile.txtがあります。

関連する問題