Java tutorial
import org.apache.poi.hssf.usermodel.HSSFCell; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author scottnumamoto */ public class Contact { private String company, address, city, state, zip, phone, site; public String getCompany() { return company; } public String getAddress() { return address; } public String getCity() { return city; } public String getState() { return state; } public String getZip() { return zip; } public String getPhone() { return phone; } public String getSite() { return site; } public Contact(HSSFCell cell1, HSSFCell cell2, HSSFCell cell3) { //Cell1 company = cell1.getStringCellValue().trim(); //Cell2 1980 Crompond Road, Cortlandt Manor, NY 10567 String parse2 = cell2.getStringCellValue().trim(); //Count how many commas are in the string int count = 0; for (int i = 0; i < parse2.length(); i++) { if (parse2.charAt(i) == ',') { count++; } } if (count == 2) { int comma1 = parse2.indexOf(','); int comma2 = parse2.indexOf(',', comma1 + 1); address = parse2.substring(0, comma1).trim(); city = parse2.substring(comma1 + 1, comma2).trim(); //if the last character of parse2 is not a digit if (!Character.isDigit(parse2.charAt(parse2.length() - 1))) { zip = "#"; state = "#"; } else { int end = parse2.length() - 1; char x = parse2.charAt(end); while (Character.isDigit(x)) { end--; x = parse2.charAt(end); } zip = parse2.substring(end + 1); state = parse2.substring(comma2 + 1, end).trim(); } } else if (count == 3) //2500 English Creek Avenue, Bldg 400, Egg Harbor Township, NJ 08234 { int comma1 = parse2.indexOf(','); int comma2 = parse2.indexOf(',', comma1 + 1); int comma3 = parse2.indexOf(',', comma2 + 1); address = parse2.substring(0, comma2); city = parse2.substring(comma2 + 1, comma3).trim(); //if the last character of parse2 is not a digit if (!Character.isDigit(parse2.charAt(parse2.length() - 1))) { zip = "#"; state = "#"; } else { int end = parse2.length() - 1; char x = parse2.charAt(end); while (Character.isDigit(x)) { end--; x = parse2.charAt(end); } zip = parse2.substring(end + 1); state = parse2.substring(comma3 + 1, end).trim(); } } else { address = "#"; city = "#"; state = "#"; } //Cell3 String parse3 = cell3.getStringCellValue(); int stop = 1000; for (int i = 0; i < parse3.length(); i++) { char c = parse3.charAt(i); if (c == '|') stop = i; } if (stop != 1000) { phone = parse3.substring(6, stop - 1); site = parse3.substring(stop + 2); } else { if (parse3.contains("one")) phone = parse3.substring(6); else phone = "#"; site = "#"; } } @Override public String toString() { return company + "/" + address + "/" + city + "/" + state + "/" + zip + "/" + phone + "/" + site; } }