Challenge 6 Solutions

Henry Simms
Henry Simms Administrator
edited June 2024 in Solutions

So did you figure it out? What approach did you take?

Post your solution below in the comments (remember to include a screenshot 📷 or a video 🎦 walk-through of your solution so others can see as well as the .dmxd file containing the function/workflow containing your solution.)

Comments

  • Josh Boxer
    Josh Boxer Administrator
    edited June 2024

    I had a go at this using the messy file. Wanted to solve it without using Regex (both for performance and simplicity), but did notice a couple of stray characters (Й and Ї) that slipped through the net!

    1. Remove/clean all non-alphanumeric characters including spaces and uppercase whatever is left
    2. Check the length of the cleaned string is 5-7 characters else replace with null/blank
    3. Extract right 4 characters as Right
    4. Pad with spaces remaining left characters to required length
    5. Concat padded left and Right strings
    6. Re-jig steps 3,4&5 for the different columns
    var Clean = UpperCase(RemoveNoise([c:Messy_Postcode], false, false, true, false));
    -- Remove non-alphanumeric and spaces then uppercase
    var Cleaned = IfThenElse(MultiCompare(Length([v:Clean]),false,false,true,{('Greater than',4), ('Less than',8)}),[v:Clean],null);
    -- Check Clean length else NULL
    var Right 4 = Substring([v:Cleaned],Subtract(Length([v:Cleaned]),3),Length([v:Cleaned]));
    -- Take right 4 characters from Cleaned
    var Left = Strip([v:Cleaned], [v:Right 4]);
    -- Strip the Right 4 characters to create Left
    var First char = Substring([v:Left], 1, 1);

    Concatenate([v:First char],Pad(Strip([v:Left], [v:First char]),2,Space,false),Substring([v:Right 4], 1, 1),Space,Substring([v:Right 4], 2, 4))