how to parse an address string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pranyht
    New Member
    • Jul 2010
    • 5

    how to parse an address string

    given an address in a string, i need to parse the address from the string and return the structure Address.

    Signature: Address parseAddress(St ring address)
    Input: String with address(e.g. “Lunkad Tower, 6th floor, \r\n Viman Nagar, \r\n Pune 411014")
    Output: The structure Address

    public class Address
    {
    public string Street {get;set;}; // Lunkad Tower, 6th floor
    public string Locality {get;set;}; // Viman Nagar
    public string City {get;set;}; // Pune
    public string State {get;set;}; // MH, Maharashtra
    public string PostalCode {get;set;}; // 60611
    public string Country {get;set;}; // e.g. India, IN
    }
    Expected Output:
    the application should parse all the given addresses in the attached input file. The output should be in a text file containing all the parsed addresses, where each parsed output address is in the following format:
    Street|Locality |City|State|Pos talCode|Country
    Each address output should be in a new line.
    In case any of the address field is missing, leave the space blank between the “|” (pipe) separators. Don’t remove the pipe separators.
    For example, if State is not mentioned in the input string, the output should be: Street|Locality |City| |PostalCode|Cou ntry

    can anyone help me write the code???
  • rotaryfreak
    New Member
    • Oct 2008
    • 74

    #2
    you can use the Java String Tokenizer class to split on certain characters

    String Tokenizer/

    You'll be able to extract the information that you need and then reassemble it in the format that you want.
    Not sure if this is the most efficient way of doing it, but it will definitely work
    Last edited by rotaryfreak; Jul 9 '10, 12:58 AM. Reason: didnt link properly

    Comment

    Working...