bptacek
asked on
List Find
Hi Everyone,
Ok, so I am pulling a String from a database field, that is a comma-delminated list. It's a list of zip codes... so for instance "00101, 44303, 55101". I need a way to find if a zip is in that list.
So with the above list, if I searched for 44303, it would come back true, but if I search the above list for 55555, it would come back false.
I just need to know how to search through that list.
Like in ColdFusion you would just go:
ListFind(list, valueToSearchFor, delimeter)
Something along the same lines as that.
Any ideas?
Thanks
Ben
Ok, so I am pulling a String from a database field, that is a comma-delminated list. It's a list of zip codes... so for instance "00101, 44303, 55101". I need a way to find if a zip is in that list.
So with the above list, if I searched for 44303, it would come back true, but if I search the above list for 55555, it would come back false.
I just need to know how to search through that list.
Like in ColdFusion you would just go:
ListFind(list, valueToSearchFor, delimeter)
Something along the same lines as that.
Any ideas?
Thanks
Ben
so, a function to do this:
boolean zipExists(String zipToFind, String zipList)
{
if ( zipToFind==null || zipList==null )
return false;
if ( zipList.indexOf(zipToFind+ ",") >= 0 )
return true;
else
return false;
}
boolean rc = zipExists( "44303", "90210, 44303, "54321" );
boolean zipExists(String zipToFind, String zipList)
{
if ( zipToFind==null || zipList==null )
return false;
if ( zipList.indexOf(zipToFind+
return true;
else
return false;
}
boolean rc = zipExists( "44303", "90210, 44303, "54321" );
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I am checking it out right now.
ben
ben
ASKER
That will do it sir! Thanks, here's your points.
Ben
Ben
String zips = "00101, 44303, 55101";
if ( zips.indexOf("44303,") >= 0 )
return true;
else
return false;