0

how can I parse a mt940 file without error by using regex or Raptorious.SharpMt940Lib?

below codes returned to me error :

  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);
        }

Error :

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

SAMPLE DATA :

: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
aloisdg
  • 22,270
  • 6
  • 85
  • 105
Penguen
  • 16,836
  • 42
  • 130
  • 205
  • I think the error message is fairly obvious. Your library is looking for the string that designates the end of the message (which you specified as '-') and it can't find it in your sample data. And according to http://martin.hinner.info/bankconvert/swift_mt940_942.pdf, your sample data doesn't look like standard mt940. – villecoder Jun 17 '16 at 14:16

1 Answers1

1

The library expects a mt940 file to have both a header and a footer. In your sample the file contains neither.

In your configuration the file should look like:

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
-
Jaco
  • 1,149
  • 1
  • 9
  • 14