Solved

List Find

Posted on 2002-06-24
5
176 Views
Last Modified: 2010-03-31
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
Comment
Question by:bptacek
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 7105170
how about indexOf ?

String zips = "00101, 44303, 55101";

if ( zips.indexOf("44303,") >= 0 )
  return true;
else
  return false;
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 7105176
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
 
LVL 33

Accepted Solution

by:
knightEknight earned 50 total points
ID: 7105178
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
 

Author Comment

by:bptacek
ID: 7105207
Ok, I am checking it out right now.

ben
0
 

Author Comment

by:bptacek
ID: 7105236
That will do it sir! Thanks, here's your points.

Ben
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now