Note that there are some explanatory texts on larger screens.

plurals
  1. POAddress String Split in javascript
    text
    copied!<p>Ok folks I have bombed around for a few days trying to find a good solution for this one. What I have is two possible address formats.</p> <pre><code>28 Main St Somecity, NY 12345-6789 or Main St Somecity, Ny 12345-6789 </code></pre> <p>What I need to do Is split both strings down into an array structured as such </p> <pre><code>address[0] = HousNumber address[1] = Street address[2] = City address[3] = State address[4] = ZipCode </code></pre> <p>My major problem is how to account for the lack of a house number. with out having the whole array shift the data up one. </p> <pre><code>address[0] = Street address[1] = City address[2] = State address[3] = ZipCode </code></pre> <p><strong>[Edit]</strong> </p> <p>For those that are wondering this is what i am doing atm . (cleaner version)</p> <pre><code> place = response.Placemark[0]; point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]); FCmap.setCenter(point,12); var a = place.address.split(','); var e = a[2].split(" "); var x = a[0].split(" "); var hn = x.filter(function(item,index){ return index == 0; }); var st = x.filter(function(item,index){ return index != 0; }); var street = ''; st.each(function(item,index){street += item + ' ';}); results[0] = new Hash({ FullAddie: place.address, HouseNum: hn[0], Dir: '', Street: street, City: a[1], State: e[1], ZipCode: e[2], GPoint: new GMarker(point), Lat: place.Point.coordinates[1], Lng: place.Point.coordinates[0] }); // End Address Splitting </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload