2017-05-12 3 views
-1

파일 경로 인 인용 부호 안에 TEXT 파일의 문자열을 읽으려고합니다. 줄에 "SSiJobPage :"가 포함되어 있고 그 옆에있는 숫자와 일치하는 경우. Like 줄에 '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); 
     }