4

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;
Nate H
  • 322
  • 1
  • 5
  • 20
  • 1
    One can assume no one ever uses FedEx to ship to Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch. – Hot Licks Sep 27 '13 at 20:53
  • So @HotLicks; you're British, but can you pronounce it :-)? – Ben Sep 27 '13 at 20:55
  • (Many years ago I handled this problem on mailing labels by switching to a narrower font.) – Hot Licks Sep 27 '13 at 20:55
  • We store addresses split into logical lines, and when we present them to carriers we crop each line at the carrier's length limit. – GSerg Sep 27 '13 at 20:56
  • @Ben - Can you pronounce "Louisville"? – Hot Licks Sep 27 '13 at 20:56
  • No idea :-). I'm going to assume Louisville, i.e. Looevil I guess. Louis being French, but I'm bound to be wrong! – Ben Sep 27 '13 at 20:59
  • @Ben - That would draw a rather pained expression in Louisville, KY, and they'd just shake their heads in Louisville, CO. – Hot Licks Sep 27 '13 at 21:19
  • 1
    @Nate H , I plan to use this code without attribution if that's ok with you? Well I converted it to PHP tho.Thx btw . – D.Tate Jul 14 '15 at 04:11
  • 1
    @D.Tate, go ahead. The reason I posted an answer on SE is to help others having similar issues. – Nate H Jul 15 '15 at 23:06

2 Answers2

3

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.

Yosem
  • 4,685
  • 3
  • 22
  • 29
2

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.

chifung7
  • 2,531
  • 1
  • 19
  • 17