Link to home
Start Free TrialLog in
Avatar of bptacek
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
Avatar of knightEknight
knightEknight
Flag of United States of America image

how about indexOf ?

String zips = "00101, 44303, 55101";

if ( zips.indexOf("44303,") >= 0 )
  return true;
else
  return false;
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" );
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bptacek
bptacek

ASKER

Ok, I am checking it out right now.

ben
Avatar of bptacek

ASKER

That will do it sir! Thanks, here's your points.

Ben