Skip to content
skwasjer edited this page Dec 9, 2021 · 13 revisions

To convert an Iban type to a string, call the ToString(IbanNet.IbanFormats format) method:

Format Format specifier Example
Electronic (default) E NL91ABNA0417164300
Print P NL91 ABNA 0417 1643 00
Obfuscated O XXXXXXXXXXXXXXXX4300

Example

IIbanParser parser = new IbanParser(new IbanValidator());
Iban iban = parser.Parse("NL91 ABNA 0417 1643 00");
Debug.WriteLine(iban.ToString(IbanFormat.Obfuscated));  // XXXXXXXXXXXXXXXX4300
Debug.WriteLine(iban.ToString("O"));                    // XXXXXXXXXXXXXXXX4300

You can also use string.Format or string interpolation using the format specifier:

// string.Format:
Debug.WriteLine(string.Format("{0:P}", iban));          // NL91 ABNA 0417 1643 00

// String interpolation:
Debug.WriteLine($"{iban:E}");                           // NL91ABNA0417164300

By convention, it is recommended to use the Electronic format when persisting an IBAN in a database, file or otherwise.