Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public static string NormalizePostcode(string postcode)
{
//removes end and start spaces
postcode = postcode.Trim();
//removes in middle spaces
postcode = postcode.Replace(" ", "");
switch (postcode.Length) {
//add space after 2 characters if length is 5
case 5: temp_postcode = temp_postcode.Insert(2, " "); break;
//add space after 3 characters if length is 6
case 6: temp_postcode = temp_postcode.Insert(3, " "); break;
//add space after 4 characters if length is 7
case 7: temp_postcode = temp_postcode.Insert(4, " "); break;
default: break;
}
return postcode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.