473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Searching a string array

AaronL
99
Hi Guys,

I was wondering if anyone could help me. Here is the situation:

I have an array of strings lets say from 1 to 1000. I want to write a function that allows the user to search for certain text in that array, and populate the results in a list box. Just like your standard search engine, given the option to put & for multiple words etc... I know it involves the InStr() function, but I'm unsure of the actual logic of the code I will want to use.

Thanks!
Feb 26 '08 #1
2 1320
VBWheaties
145 100+
Hi Guys,

I was wondering if anyone could help me. Here is the situation:

I have an array of strings lets say from 1 to 1000. I want to write a function that allows the user to search for certain text in that array, and populate the results in a list box. Just like your standard search engine, given the option to put & for multiple words etc... I know it involves the InStr() function, but I'm unsure of the actual logic of the code I will want to use.

Thanks!
Heres two functions that should give you an idea of how I would do it.
You can pass in 1 or more strings in FindStrings.
For each value in the Paramarray, call IsInArray to return a boolean if the string exists in the array.

Expand|Select|Wrap|Line Numbers
  1. Public Function FindStrings(ParamArray Searches() As String) As Boolean
  2.    Dim i As Integer
  3.    For i = 0 to UBOUND(Searches) - 1
  4.       If IsInArray(Searches(i)) = FALSE Then 
  5.          FindStrings = False
  6.          Exit Function 
  7.       End If 
  8.    Next 
  9.    FindStrings = True
  10. End Function 
  11. Public Function IsInArray(szSearch As String) as Boolean
  12.    'ToDo: Write code to iterate array and look for szSearch. 
  13. End Function 
  14.  
Feb 26 '08 #2
Killer42
8,435 Expert 8TB
Whether you use the Instr() function or not depends on the type of match you're looking for. If you only want to check an entire string to see whether it matches, you would just use the = operator. If you want to see whether your string appears anywhere within another string, then you would probably use Instr() to test it.

On the other hand, you might use the Like operator to allow wildcard matching. Have a look at this example...
Expand|Select|Wrap|Line Numbers
  1. Dim a As String, b As String, c As String
  2. a = "ABCDEFG"
  3. b = "ABC*"
  4. c = "ABC"
  5. Debug.Print "B:"; (a Like b)
  6. Debug.Print "C:"; (a Like c)
  7.  
Feb 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Sims | last post by:
Hi, Given a string $txt and an array of strings $txt_array what would be the best/fastest way to search in _insensitive_ case if $txt is in $text_array and, if it is, where is it? Because I...
3
by: hivie | last post by:
I have a problem that is causing me problems. I have a text file that stores 5 lines of crap (stuff that I dont need( for the user only)). After that there is data that is in three columns...
5
by: Richard Berg | last post by:
Hello, I need to search a byte array for a sequence of bytes. The sequence may include wildcards. For example if the array contains 0xAA, 0xBB, 0xAA, OxDD then I want to be able to search for...
5
by: Ada | last post by:
hello folks, just wanna get some feedback from someone here who has more experience. :-) i'm developing a small app that require searching for the highest index within a directory. i was...
5
by: Dan | last post by:
I wonder if anyone has suggestions for reducing the amount of time it would take to search my array using the function that I have written. I want to find a position in the array of an item that...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
3
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a...
15
by: DavidW | last post by:
Hello, Is the function below the simplest way to produce an iterator to the next non-space in a string? (Or the upper-bound iterator if none is found). Searching for a sequence is overkill and...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
3
by: jac130 | last post by:
the program runs, and user is prompted via inputbox to enter an integer-this is the size of the array, then the user fills the array with that many values...but as the user enters the values, i need...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.