2017-05-12 4 views
-1

ファイルパスである引用符 ''内のTEXTファイルから文字列を読み取ろうとしています。行に "SSiJobPage:"が含まれていて、その行の横にある番号と一致する場合。同様に、行に 'SSiJobPage:8'が含まれている場合は、 'SSiJobFileRef:8'の行に移動し、その隣に 'C:\ folderName \ 012M032.filename.p1.pdf'というファイルパスを取得します。また、すべての 'SSiJobPage:'を見つけるまで実行されます。 'C#でどうすればいいですか?C#を使用してテキストファイル内の一致する数字と文字列を見つける方法

ありがとうございます!たぶん

>%SSiJobFileRef: 2 'C:\folderName\210C001-3.filename.p1.pdf' 2 -1 0 0.00000 
     >%SSiJobFileRef: 3 'C:\folderName\210C001-3.filename.p2.pdf' 3 -1 0 0.00000 
     >%SSiJobFileRef: 4 'C:\folderName\210C001-3.filename.p3.pdf' 4 -1 0 0.00000 
     >%SSiJobFileRef: 5 'C:\folderName\210C001-3.filename.p4.pdf' 5 -1 0 0.00000 
     >%SSiJobFileRef: 6 'C:\folderName\210C001-3.filename.p5.pdf' 6 -1 0 0.00000 
     >%SSiJobFileRef: 7 'C:\folderName\210C001-3.filename.p6.pdf' 7 -1 0 0.00000 
     >%SSiJobFileRef: 8 'C:\folderName\012M032.filename.p1.pdf' 8 -1 0 0.00000 
     >%SSiJobFileRef: 9 'C:\folderName\002M052.filename.p1.pdf' 9 -1 0 0.00000 
     >%SSiJobFileRef: 10 'C:\folderName\012M042.filename.p1.pdf' 10 -1 0 0.00000 
     >%SSiJobFileRef: 11 'C:\folderName\002W000.filename.p1.pdf' 11 -1 0 0.00000 
     >%SSiJobFileRef: 12 'C:\folderName\012B000.filename.p1.pdf' 12 -1 0 0.00000 
     >%SSiJobFileRef: 13 'C:\folderName\002W100.filename.p1.pdf' 13 -1 0 0.00000 
     > 
     >%SSiJobPage: 8 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 9 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 10 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 2 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 3 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 11 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 12 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 4 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 5 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 13 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 14 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 6 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 7 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 15 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 16 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 17 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 8 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 21 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 10 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
     >%SSiJobPage: 18 1 0.00000 0.00000 1.00000 1.00000 3 0.00000 0.00000 '' 0 
+0

、その後、コメントはありません。 – Sky

答えて

1

そうのようなもの:あなたはどんな答えを持っていない場合は

public class SSiJob 
{ 
    public int id { get; set; } 
    public string path { get; set; } 
    public bool matched { get; set; } 
} 

     List<SSiJob> jobs = new List<SSiJob>(); 

     using (StreamReader sr = new StreamReader(@"D:\CYA\Test2.txt")) 
     { 
      string stringy; 
      while ((stringy = sr.ReadLine()) != null) 
      { 
       string[] words = stringy.TrimStart().Split(' '); 
       if (words[0] == ">%SSiJobFileRef:") 
       { 
        jobs.Add(new SSiJob { id = Convert.ToInt32(words[1]), path = words[2] }); 

       } 
       else if (words[0] == ">%SSiJobPage:") 
       { 
        var check = jobs.Where(a => a.id == Convert.ToInt32(words[1])).FirstOrDefault(); 
        if(check != null) 
        { 
         check.matched= true; 
        } 
       } 
      } 
      jobs.RemoveAll(a => a.matched == false); 
     } 
関連する問題