An Eircode is an Irish postal code.
dotnet add package RecursiveAI.OneContactRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneContact; var address = PostalAddress.Parse( "Sample Studio, 12 Example Road, " + "Macroom, Co. Cork, t37f8hk", Region.Parse("IE")); Console.WriteLine( address.ToString(AddressStyle.Postal));
Unzip the example, then dotnet run.
Prints this mailing label:
Sample Studio 12 Example Road MACROOM CO. CORK T37 F8HK
Region.Parse("IE") selects Ireland. If OneContact can’t parse the text as an address, PostalAddress.Parse throws ContactParseException. The example uses an illustrative address: formatting doesn’t establish that the Eircode belongs to the address or that mail can be delivered there.
Variations
Add the country for mail sent from abroad. Replace the final Console.WriteLine with this call. It adds IRELAND below the Eircode.
Console.WriteLine(address.ToString( AddressStyle.Postal, includeCountry: true));
Related recipes
The short answer
Pass the pasted address to PostalAddress.Parse with Region.Parse("IE"), then call ToString(AddressStyle.Postal). In the example, the commas separate the addressee, street, town, county, and Eircode. The output puts them on separate lines and changes t37f8hk to T37 F8HK. There’s no need to split the input at commas or insert the Eircode space yourself.
How do you format an Irish address?
Put the recipient first, then the house number or name and the street or townland, followed by the postal locality and the county if it’s part of the address. In the Irish address rules, Co. or County above the Eircode marks the county. The example prints MACROOM above CO. CORK and keeps the CO. abbreviation. Follow the supplied postal address: An Post notes that the postal county can differ from the geographic county and that Dublin postal district numbers should be included where applicable.
An Post puts the Eircode last on domestic mail and second to last on mail from abroad, above the country. Leave includeCountry at its default for the domestic label in the example; use true when the destination country needs a line of its own.
What is the format of an Irish Eircode?
There are seven characters, written as three characters, a space, and four characters. T37 F8HK is the form shown in the UPU’s Ireland addressing sheet. Keep the Eircode as text, not a number. OneContact can read the unspaced input above and insert the space for the label; it does not fill in characters that were never supplied.
How do you find an Eircode for an address in Ireland?
Use An Post’s address lookup when the Eircode is missing or you need to check that it matches the address. OneContact formats the address and Eircode you supply using local rules. It does not query an address database, find a missing Eircode, or replace your postal county with one inferred from a map.