using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IBANNummerPrüfen { public class IbanPrüfung { // Richtiges IBAN Format: DE68 2105 0170 0012 3456 78 //private string? IBAN; private string? ibanCleared; private string? ibanSwapped; private string? sum; private string? iban; public void SetIbanPrüfungEntgegennehmen() { Console.Write("Bitte geben Sie ihre IBAN-Nummer ein: "); this.iban = Console.ReadLine(); Console.WriteLine(IBANPrüfung()); } /// /// Bestimmt ob die Checksumme einer IBAN gültig ist /// /// Der zu prüfende IBAN (z.B: "DE68 2105 0170 0012 3456 78") /// True, wenn gültig ist. Andernfalls False. public bool IBANPrüfung() { if (this.iban != null) { this.ibanCleared = this.iban.ToUpper().Replace(" ", "").Replace("-", "").Replace(".", ""); //Console.WriteLine(ibanCleared); this.ibanSwapped = ibanCleared.Substring(4) + ibanCleared.Substring(0, 4); //Console.WriteLine(ibanSwapped); this.sum = ibanSwapped.Aggregate("", (current, c) => current + (char.IsLetter(c) ? (c - 55).ToString() : c.ToString())); //Console.WriteLine(sum); //this.sum = ibanCleared.Aggregate("", (current, c) => current + (char.IsLetter(c) ? (c - 55).ToString() : c.ToString())); var d = decimal.Parse(sum); return ((d % 97) == 1); } return false; } } }