Question

We're using FedEx as our shipper. Their label printer limits us to 35 characters per address line. My co-workers are I are discussing about splitting the address line into a second address line if the first line goes over the 35 char limit. We're also running into this issue when using their Address Validation Service.

I'm curious, how have other people handled the 35 character limit?

Thanks in advance!

EDIT

Posting the solution I developed so it may help someone else (written for Perl and variable names changed to protect the innocent).

# handle too long strings
my $street1_string = sprintf( "%s", $ShipTo_Street_Line1 ) );
my $street2_string = sprintf( "%s", $ShipTo_Street_Line2 ) );
my $street1_final;
my $street2_final;
my $street1_length  = length($street1_string);
my $last_space_pos = rindex($street1_string, ' ');

# find and split on last space less than 35 characters
while($last_space_pos >= 35)
{
    if ($last_space_pos < 35)
    {
        break;
    }

    $last_space_pos = rindex($street1_string, ' ', $last_space_pos-1);
}

$street1_final = substr($street1_string, 0, $last_space_pos);
$street2_final = substr($street1_string, $last_space_pos+1, $street1_length) . ' ' . $street2_string;
Was it helpful?

Solution

Yes, you a right, the character limit can be troublesome. I have used a method that isn't exactly elegant but it works. Look for all the 'spaces' in the string and split the string at the space that is closest to but less than 35 and put the excess in Address line 2. You will note that address line two is also only 35 characters.

OTHER TIPS

I needed to deal with usps and ups labels before. In addition to 35 characters limit, there are also three address lines limit. If an address line is longer than 35 characters, I'll try to split after a "comma". If a comma doesn't exist, split the space which is closest to the end of the line. If there are already three address lines, I'd move the extra address line to the "company" field (a shipping label has contact, company, and 3 address lines fields). If there are more than two address lines required splitting, and all 3 address lines are used, then fail with errors. This happened once in hundred thousands addresses.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top