Challenge 6 - Postcode Formatting

Henry Simms
Henry Simms Administrator
edited June 5 in Challenges

This challenge came from a question that I was asked recently. The user had a column of UK postcodes looking something like this:

Input file:

The challenge is to reformat these values based on strict requirements, and provide 2 new output fields containing:

8 byte format. All values are 8 characters. Examples of this standard (where _ represents a space) are:

  • AB10_1AF
  • B__1_1AA
  • B_11_1AA
  • AB9A_9AA

7 byte format. All values are 7 characters. Examples of this standard (where _ represents a space) are:

  • AB101AF
  • B1__1AA
  • B11_1AA
  • AB9A9AA

I hope you enjoy giving this challenge a go. There are lots of approaches to solving this so I'm looking forward to seeing the range of your ideas. Once you're ready, please post your solutions here.

If you found the first task too easy, here's a more advanced input file containing much "messier" data (which is UTF-8 encoded):