2016-06-17 108 views
0

如何使用正則表達式或Raptorious.SharpMt940Lib解析mt940文件而不出錯?如何使用正則表達式或Raptorious.SharpMt940Lib解析mt940文件?

下面的代碼返回給我的錯誤:

var header = new Raptorious.SharpMt940Lib.Mt940Format.Separator("STARTUMSE"); 
     var trailer = new Raptorious.SharpMt940Lib.Mt940Format.Separator("-"); 
     var genericFomat = new Raptorious.SharpMt940Lib.Mt940Format.GenericFormat(header, trailer); 

     using (var fileStream = new FileStream(@"C:\test\ex.txt", FileMode.Open, FileAccess.Read)) 
     { 
      TextReader tr = new StreamReader(fileStream); 
      var parsed = Raptorious.SharpMt940Lib.Mt940Parser.Parse(genericFomat, tr); 
     } 

錯誤:

An unhandled exception of type 'System.IO.InvalidDataException' occurred in Raptorious.SharpMt940Lib.dll 
Additional information: Can not find trailer! 

示例數據:

:20:6307396651830602 
:25:0010-01941/63073966-5183 
:28C:00578/001 
:60F:C155602TRY2683629,41 
:61:1606055Y4774,04NERRNONREF 
:86:GOND: HARRAN MAL.OD.HES20160602/201600000003267 S.GN.EMR OKUL 490 
5631 NOLU ABONENIN ELEKTRIK TUKETIM BEDELI 
:61:160602CY591,20NEFRRONREF 
:86:GOND: BIRECIK MA.OD.HES20160602/201600000003244 S.GN.EMR AYggN CP 
AL 4914861 NOLU ELEKTRIK ABONESININ FATURA ODEMESI 
:61:160602CY2188,54NERRNONREF 
+0

我認爲錯誤消息是相當明顯的。您的庫正在查找指定消息結尾的字符串(您指定爲' - '),並且它在示例數據中找不到它。根據http://martin.hinner.info/bankconvert/swift_mt940_942.pdf,您的示例數據看起來不像標準mt940。 – villecoder

回答

1

庫需要一個MT940文件有兩個頭和頁腳。在你的示例中,該文件不包含任何內容

在您的配置文件應該是這樣的:

STARTUMSE 
:20:6307396651830602 
:25:0010-01941/63073966-5183 
:28C:00578/001 
:60F:C155602TRY2683629,41 
:61:1606055Y4774,04NERRNONREF 
:86:GOND: HARRAN MAL.OD.HES20160602/201600000003267 S.GN.EMR OKUL 4905631 NOLU ABONENIN ELEKTRIK TUKETIM BEDELI 
:61:160602CY591,20NEFRRONREF 
:86:GOND: BIRECIK MA.OD.HES20160602/201600000003244 S.GN.EMR AYggN CPAL 4914861 NOLU ELEKTRIK ABONESININ FATURA ODEMESI 
:61:160602CY2188,54NERRNONREF 
-