• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

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
0
bptacek
Asked:
bptacek
  • 3
  • 2
1 Solution
 
knightEknightCommented:
how about indexOf ?

String zips = "00101, 44303, 55101";

if ( zips.indexOf("44303,") >= 0 )
  return true;
else
  return false;
0
 
knightEknightCommented:
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" );
0
 
knightEknightCommented:
hmm, maybe you don't need to look for the comma (in case it is at the end of the list)

if ( zipList.indexOf(zipToFind) >= 0 )
0
 
bptacekAuthor Commented:
Ok, I am checking it out right now.

ben
0
 
bptacekAuthor Commented:
That will do it sir! Thanks, here's your points.

Ben
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now