Formatting Postal Addresses

I'm a legacy programmer rather new to java. The company I'm working for has decided (finally) to get more involved with the www.
One thing I am working on, is providing customer information online. I'm using the legacy database that currently holds customer info. My problem is that everything is in all caps. How can I make this:
555 MEMORIAL DRIVE
ANYWHERE US 35555-5555
Look like this:
555 Memorial Drive
Anywhere, US 35555-5555
I used the following code for the name, which was relitively easy:
fullName = firstName.charAt(0) + firstName.trim().toLowerCase().substring(1) + " " +     
     lastName.charAt(0) + lastName.trim().toLowerCase().substring(1);
I'll be continuing my online research but I thought someone here might have some good advice for me.
Thanks in advance for the info!
bfrmbama

Rather than using strings, I created a character array and then manipulated the array elements. It seems to have more flexibility. I accomodated all of your example (except the comma following the state, which your code also doesn't handle) and DrClap's suggestion. The handling of the state abbreviation is not pretty, but unless you have some additional information such as positional information, word count location, etc, or an external source to identify state abbreviations, I doubt that much more can be done.
The best solution might be a combination of character array and string processing.
public class AddressFix
    public static void main(String[] args)
        // sample data
        String[] input = new String[2];
        input[0] = "555 n. MEMoRiAL dRIVE";
        input[1] = "ANYWHERE-viLLE us 35555-5555";
        AddressFix addr = new AddressFix();
        for (int n = 0; n < input.length; n++)
            System.out.println(addr.fixup(input[n]));
    String fixup(String in)
        String line = in.toLowerCase();
        // remove multiple spaces
        line = line.replaceAll(" +", " ");
        char[] lineArray = line.toCharArray();
        char priorChar = ' ';
        for (int n = 0; n < lineArray.length; n++)
            char letter = lineArray[n];
            // this char is a letter
            if (Character.isLetter(letter))
                // prior char is not a letter
                if (!Character.isLetter(priorChar))
                    lineArray[n] = Character.toUpperCase(letter);
                // so, prior char is a letter and if these 2 letters
                // are surrounded by spaces, assume a state abbrev.
                else if (n > 1     // needed to keep array in bounds
                     && n < (lineArray.length - 1)          // ditto
                     && lineArray[n - 2] == ' '
                     && lineArray[n + 1] == ' ')
                    lineArray[n] = Character.toUpperCase(letter);
            priorChar = letter;
        return new String(lineArray);
}OUTPUT:
555 N. Memorial Drive
Anywhere-Ville US 35555-5555

Similar Messages

  • Postal address listed in reverse order

    My postal addresses in my adress book are now in reverse order, in other words listed zip first, state, city, street?
    It only changed on my iphone? My Mac is fine, my iPad too. Any ideas?
    Bobby

    Check Settings>General>International>Region Format and make sure that it's set to your location.

  • How can I modify an incorrect mailing address on my AppleCare Protection Plan certificate? After I registered a new product with AppleCare I realised that I'd entered the wrong postal address and I need to update it to show my correct address.

    I need to modify an incorrect mailing address on my AppleCare Protection Plan certificate. After I registered a new product with AppleCare I realised that I'd entered the wrong postal address during the registration process and now I need to update my details to show my correct address. I've been trying for several hours to find a way to modify my address on the AppleCare site, with no success. Any help/advice would be greatly appreciated!

    Contacting Apple World Wide for Support and Service
    http://support.apple.com/kb/HE57
    Apple Contact USA
    http://www.apple.com/contact/

  • Export postal address from address book

    Is there a way to export all of my postal address' from my address book to sticky labels for postage?

    You should print them (link).

  • Can anyone tell me a postal address to allow me to...

    Good evening folks,
    I've had a pretty horrible time dealing with BT customer services recently. I've needed to contact them because my broadband has for quite a few months now has been dropping constantly, and even when it recovers it's often at a disgracefully low speed (for example as I write this I've got a .15 meg connection).
    I've made umpteen telephone calls and had many difficult conversations with people with accents that I find difficult to understand or be understood. I've tried verbally to explain that I now want to complain, especially as no one will take ownership beyond the duration of the call for fixing my problem. I finally managed to get an engineer to attend earlier this week, who couldn't find anything wrong, and the connection is back to its old tricks of constantly dropping. The thought of having to deal with BT's customer services again is actually a source of considerable anxiety and is making me feel I'll on occasion. I've had enough and want to complain in writing by recorded delivery, including my MP, but I can't find a postal address anywhere on the website.
    Can anyone help? Does anyone have for example got an address for a chairman or other suitably senior person?

    IMJolly,
    i ran the checker and got this
    Telephone Number xxx on Exchange CAMBUSLANG is served by Cabinet 14
    Featured ProductsDownstream Line Rate(Mbps)Upstream Line Rate(Mbps)Downstream Range(Mbps)Availability Date  High Low High Low    
    FTTC Range A (Clean)
    54.5
    54.5
    18
    18
    31-May-14
    FTTC Range B (Impacted)
    54.5
    54.5
    18
    18
    31-May-14
    WBC ADSL 2+
    Up to 7.5
    4.5 to 11
    Available
    WBC ADSL 2+ Annex M
    Up to 7.5
    Up to 1
    4.5 to 11
    Available
    ADSL Max
    Up to 4.5
    3.5 to 7.5
    Available
    WBC Fixed Rate
    2
    Available
    Fixed Rate
    2
    Available
    Other Offerings
    Fibre Multicast
    31-May-14
    Copper Multicast
    Available
    John,
    Yes we have one extension, but it is not currently used. My wife complains that the noise on that line is very poor.
    Ectophile,
    Thanks for address.

  • Brand New Macbook Air. How to update iPhoto without giving postal address?

    I have a brand new New Macbook Air. Since the same day I bought it I keep getting software update notifications for iPhoto and iMovie, but when I try to download them Apple asks for my postal address and phone numbers. This is outrageous. Apple will not allow me to leave any address fields blank. No way are they are  going to get my address to put on their database, I would rather switch off iPhoto and iMovie update notifications, but can't see a way to do this. Can anyone help?

    Have you tried calling Apple Care?  They're very helpful and could help you trouble-shoot this.
    I agree with you-- one should not have to give one's credit card and address information, unless one wants to, to get an update.
    Even on a purely practical level, there are people who do not have credit cards.
    One other thought-- these are updates, right?  Or, are they pitches for a new version of the software programs-- which could have to be purchased?  If they are new progrms, in which case, you would have to supply credit card and address to buy them.

  • Customer services postal address?

    I want to send a formal complant letter to BT but can not find an postal address anywhere! You would think they are hiding on purpose...
    Does anyone have a postal address for customer services? I do not want to use the email link as that will most likely lead to yet more pointless telephone conversations with people that cannot help.
    thanks in advance.

    Hi Guys,
    Thanks for posting. I'm sure I can help with any complaints you might have. Utopian, did you receive any further responses from us? Can you check your junk folder just in case it's slipped in there. The address posted by Pasha is correct but if you want to drop me an email to [email protected] I'll be happy to look into any queries you might have.
    Ta
    David
    BTCare Community Mod
    If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
    We are sorry but we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-)

  • Does the 8310 display full postal addresses?

    Hello, I have just synchronized my blackberry 8310 with the desktop manager. It has imported all of my contacts onto my phone however, I can not get the phone to display the entire postal address for my contact....it will only display the city and postcode. Is there a way to change the settings to display this?

    did you try to fill in the address manually ?
    I have many fields for the Home address :
    - Address 1
    - Address 2
    - City
    - State/Prov.
    - Zip/Postal Code
    - Country
    if it works that way, it means you have to set up the synchronization betweeb your WAB (Windows Address Book) and the Blackberry. There's a screen in your Blackberry Desktop Manager to tell which field in the WAB goes to which field in the Blackberry contact.
    The search box on top-right of this page is your true friend, and the public Knowledge Base too:

  • Table for Email and Postal Address for payers

    Hi ,
    I would like to know how to download email address and postal address of list of payers i have. Which is the table that has this data?

    Dear Vinod,
    Addresses of both Customers & Vendors is stored in ADRC tabbe. ADRC is master table of all Addresses in  the system.
    From KNA1 take Customer Code & Address field.
    From ADRC take list of all address. Here Address Number field is same as Address field in Csutomer Master. 
    In Excel run Vlookup on above two files with Address & address numbers feilds as common.
    Hope the above is useful..
    Reward if you like to..
    Thanks,
    Jignesh Mehta
    Mumbai
    98700 10230

  • Gconsync drops postal addresses with big Address Book changes?

    After many years of procrastinating, I've thrown a lot of contacts into my Address Book just in time to send Christmas cards.  I've configured Address Book to talk with Gmail, which causes gconsync to run once an hour. 
    I've observed that when I do large amounts of changes in Address Book, like a dozen or so in an hour, the postal addresses of random contacts get lost at the Google end.  Once this happens, efforts to fix the contacts one-by-one seem pointless.  I have to save/export my Mac Address Book, delete contacts at both ends, then reload from my backup to make things right.
    Anyone else seen this behavior? 

    Finally fixed it.  I am quite sure one of your address books is messed up.  To fix it:
    1. Figure out which address book is messed up.  I have three, iPhone, iPad, iMac. Shut off iCloud on one of them and try address book updates on the other two.  When the problem disappears, you will know which address book is messed up.
    2. Next fix the address book on the errant device.  I did it by restoring, WITHOUT using a backup.  Can't use a backup because the same error will be there.  This is a pain because you need to reorganize your aps, logins etc.  So, you might want to try shutting off iCloud and removing the address book from the device.  Then turn iCloud back on.  It will load a new address book.  I don't know if this will fix the problem. Might be hidden files that have the problem.
    3. This, by the way, also caused a huge power drain for me.  You can tell if you have the same problem by opening address book and checking if it is continually trying to sync.
    Bob
    [email protected]

  • Parsing Postal Address

    I'm writing a web-based application and I need to parse the line 1 of an address. I was wondering if there is an API to do this for me. I didn't see anything in the JavaDocs. I need to parse the address and then validate it. The validation isn't as necessary since I have access to a database and can check for addresses and.or closely matching addresses already. I just need to make sure I'm getting the correct information from the text field.
    So any tips on parsing a US Postal address?
    thanks

    If I asked that question, it is just because I happen to work in the field of semantic extraction and this is definitely not a simple question.
    Still, since this is 'only' about postal addresses, you might be able to program some filters :
    - one for the Zip code with that kind of use :
    ZipCodeFilter myZipCodeFilter = new ZipCodeFilter();
    boolean foundZipCode = myZipCodeFilter.isZipCode(myString);
    - a filter for the towns. For this one the best way is to find a lexicon somewhere on the web that contains all US town names. Best luck on that.
    - for the street address, this is a lot trickier. You have to have a good idea about how they normally look like. When given a street address, you want to verify that it follows a certain given pattern. That is possible only if you already have found the street number, the street type (boulevard, street, road, avenue and all their other written forms, bd, st, rd, av...) and finally the street name itself.
    This is really not simple so you really would be better off giving a definite pattern to your users.
    Hope this helps and is not completely out of the subject.

  • HT201401 Postal address

    I've just registered to send my i phone for a service. However I did not see a postal address I am supposed to send my faulty device too?

    You will have to restore your phone to get rid of it. 

  • Change postal address

    I would like to know how to change my postal address please... I can't do it on my account, there is just the option for e-mail address. Thank you

    You will have to ring EE and speak to customer service then.

  • Postal address for iTunes Store Canada?

    As I can't get any help or comment from Apple online on important functionality they have removed I wish to send them a letter on paper and cannot find any postal addresses anywhere on their sites. I want to write specifically about iTunes Store Canada--any likely part of the org. to mail to would be appreciated.
    THANKS, anyone.
    EBG

    Apple Canada
    7495 Birchmount Road
    Markham, ON
    L3R 5G2

  • Postal address, present, absent

    I have a E-5 and  I use Outlook.  I have found frustrating not to be able to write a  postal address on the phone itself, but since it works through Outlook, it is an minor  inconvenience. What is more puzzling to me is that some addresses appear  in the phone under the name, others not, even though it is possible to find them when choosing  "posting details".  I would like to know what makes the address appear / disappear under the name....

    The exit event on the postal address postal code calls the click event on the check box "duplicateAddress".
    // form1.page1.address4b::exit - (JavaScript, client)
    // fire script in checkbox
    duplicateAddress.execEvent("click")
    // form1.page1.duplicateAddress::click - (JavaScript, client)
    if (this.rawValue == 1)
      address1b.rawValue = address1a.rawValue;
      address2b.rawValue = address2a.rawValue;
      address3b.rawValue = address3a.rawValue;
      address4b.rawValue = address4a.rawValue;
    else
      address1b.rawValue = null;
      address2b.rawValue = null;
      address3b.rawValue = null;
      address4b.rawValue = null;
    If "duplicateAddress" has not been selected its off value is 0 (zero) so it resets all the postal address fields.
    Steve

Maybe you are looking for