2016-08-14 2 views
0

IgnoreFirst (int) 또는 IgnoreLast (int)는 머리말이나 꼬리말로 고정 된 행 수만 무시합니다. 하지만 txt/csv 파일의 특정 줄을 무시하거나 주석을 달고 싶습니다. 다음과 같은 예를 들어 (일부 단락 또는 TXT/CSV에서 특정 라인을 무시) : 나는 BeforeReadRecord 및 SkipThisRecord에 대해 읽고FileHelpers를 사용하여 txt 파일의 행을 주석으로 추가하거나 무시하는 방법

############# This is a comment ########## 
/* Some comment paragraph 
some more comments 
last line of comment */ 
1,Foo,FooItem1 
2,Foo,FooItem2 
3,Goo,GooItem3 
#4,Doo,DooItem4 <-- ignore. 
5,Eoo,EooItem5 

잠재적으로이 문제를 해결할 수 있지만 문서는 이미지로 간단하고, 설명이 없거나 예제를 제공하지 않습니다. 기록을 건너 뛸

FileHelperEngine engine = new FileHelperEngine(typeof(Orders)); 
// set the event here 
engine.BeforeReadRecord += new BeforeReadRecordHandler(BeforeEvent); 

다음 핸들러에서, 특정 조건을 확인 할 수 있습니다 :

enter image description here

답변

5

이벤트 핸들러를 등록하기 위해이 같은 것을 사용해야합니다

private void BeforeEvent(EngineBase engine, BeforeReadRecordEventArgs e) 
{ 
    // skip any bad lines 
    if (e.RecordLine.StartsWith("#") || e.RecordLine.StartsWith(" ")) 
     e.SkipThisRecord = true; 
} 

정수로 시작하는지 확인하고 건너 뛰면 건너 뛸 수 있습니다.

편집 :

public class OrdersFixed 
    :INotifyRead 
{ 
    //... 

    public void BeforeRead(BeforeReadEventArgs e) 
    { 
     if (e.RecordLine.StartsWith(" ") || 
      e.RecordLine.StartsWith("-")) 
      e.SkipThisRecord = true; 
    } 

} 
: 당신은 또한이 같은 기록 내부의 INotifyRead 인터페이스를 사용할 수 있습니다
관련 문제