diff --git a/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt b/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt index 98dafa19..c4f3f241 100644 --- a/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt +++ b/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt @@ -75,13 +75,15 @@ open class Mt940Parser : IMt940Parser { override fun parseTransactionsChunk(mt940Chunk: String): Pair, String> { try { - val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940Chunk) + val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940Chunk).toMutableList() + + var remainder = "" + if (singleAccountStatementsStrings.isNotEmpty() && singleAccountStatementsStrings.last().isEmpty() == false) { + remainder = singleAccountStatementsStrings.removeAt(singleAccountStatementsStrings.lastIndex) + } val transactions = singleAccountStatementsStrings.mapNotNull { parseAccountStatement(it) } - val remainder = if (singleAccountStatementsStrings.size == transactions.size + 1) singleAccountStatementsStrings.last() - else "" - return Pair(transactions, remainder) } catch (e: Exception) { log.error("Could not parse account statements from MT940 string:\n$mt940Chunk", e)