Created
November 19, 2017 05:48
-
-
Save naveed-ahmad-biz/44f5daca0b7ec741fdf4fafa819784cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 could just do
temp_postcode = temp_postcode.Insert(postcode.Length - 3, " ");
wonder if this works internationally though?