Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract Values from UK Post Codes 1

Status
Not open for further replies.

slickp

Technical User
Feb 15, 2006
35
GB
I've got a list of UK postcodes but need to extract the area the district and the sector from it. e.g

MK40 3DJ would be:

Area:MK
District:40
Sector:3

However some UK postcodes have only one letter for the area and others have two, also the same can be said for the district can either be 1 number or 2 numbers.

Can anybody help with a formula? Got a brain block from this bloody heat!!
 
Right I've managed to get the area extracted.

Can anyone help on the district:

A sample of the post codes I'll be using are:

N1 0EN - would want to extract 1
MK44 1DZ - would want to extract 44
SW3 5DJ - would want to extract 3

Any help please?
 
I'm not familiar with UK postcodes. Do they always take one of the following formats where A = any letter and 1 = any digit?

A1 1AA
AA1 1AA
A11 1AA
AA11 1AA

-LB
 
Yep always the format above, thats why this extraction is a bit of an arse!!
 
//{@Area}:

local stringvar x := split({table.postcode}," ")[1];
local numbervar i;
local numbervar j := len(x[1]);
local stringvar area;

for i := 1 to j do(
if not isnumeric(x) then
area := area + x
);
area

//{@District}:
local stringvar x := split({table.postcode}," ")[1];
local numbervar i;
local numbervar j := len(x[1]);
local stringvar district;

for i := 1 to j do(
if isnumeric(x) then
district := district + x
);
district

-LB
 
I tried this and it seemed to work:

if isnumeric (right((split({CLIENT.PostCode}," ")[1]), 1)) and isnumeric (right((split({CLIENT.PostCode}," ")[1]), 2)) then right((split({CLIENT.PostCode}," ")[1]), 2) else
if isnumeric (right((split({CLIENT.PostCode}," ")[1]), 1)) and not (isnumeric (right((split({CLIENT.PostCode}," ")[1]), 2))) then right((split({CLIENT.PostCode}," ")[1]), 1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top