Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable contained in an array

Status
Not open for further replies.

qwicker

Programmer
Feb 16, 2005
12
0
0
US
Hello again:

I have an array with many elements. What would be the most efficient way to check to see if a string is contained somewhere in that array, line by line? I suppose a foreach loop?
 
you will have to check line by line, or element by element of the array. It might be faster to use a loop and the "last" flow control operator if these are big arrays and you only need to know if the variable is in the array and not how many times it's in the array. grep is fast though and you would have to run checks with your actual data to see which method is better for our situation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top