5 Replies Latest reply on Dec 10, 2009 2:18 PM by DLake

# Parsing

### Title

Parsing & Testing if Text or Number

### Post

We have a field in our db soon to be used for both Canadian postal codes and US zip codes (but currenly only zip codes).  I'm currently pulling the left 3 characters of the zip to determine the appropriate shipping zone.  (ie 63343 results in 633 and the match in my zone table = 5, zone 5 then determines shipping rate per lb).

We are starting to sell into Canada where postal codes start with an alph character (ie, L4325, H4432).  I'd like a calc that does the following:

Determines the postal code origin by testing the first character in the field to determine if it's a alpha or numeric character.

If alpha, then pull the first left most character (a single letter)

If numeric, then pull the three left most characters (the first three of the US Zip)

Thanks,

David

• ###### 1. Re: Parsing & Testing if Text or Number

Let ( L = Left(PostalCodeField ; 1 ) ;

If ( isempty( getasnumber ( L ) ) ; L ; Left (postalcodefield ; 3 ) ) )

• ###### 2. Re: Parsing & Testing if Text or Number

Try:

Let ( [
char = Left ( Zip ; 1 )
] ;
Case ( char ; Left ( Zip ; 3 ) ; char )
)

• ###### 3. Re: Parsing & Testing if Text or Number
Sorry for the confusion, but I don't understand the capital L used in your formula.  The Canadian codes can be anything from A-Z, less a couple options.  Does this matter?
• ###### 4. Re: Parsing & Testing if Text or Number
L is a temporary variable defined by the Let function and assigned the value of the first character in the zip code field. In comment's version, he named this variable "char".
• ###### 5. Re: Parsing & Testing if Text or Number
Thank you both so much. As you knew, both recommendations worked seamlessly.  I've been using FMP since 2.0.  I'm not formally trained programmer, and I can tell in situations like this that more formal training would be helpful.  Thanks again!