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

How to find contents of a table in a string

Given a string, usually a long sentence, how will I know if the contents of my table is part of that string.

ex. string = "the quick brown fox jump over the lazy dog"
myTableContents = dog, cat, fox, pig

I wanna get all the words from the string that exists in my table.  How will I do that using C#.net, and I'm using Access database.

0
meredithf
Asked:
meredithf
1 Solution
 
miketobCommented:
Use the split method to separate your sentence into words, it will result in an array of words, then cycle through this arry serching for each word in your table.

Regards

0
 
Bruce_1975Commented:
Just to give you an other idea
Regards,
Bruce
string givenString = "the quick brown fox jump over the lazy dog";
foreach (string item in myTableContents)
{
    if (givenString.IndexOf(item) > -1)
        Debug.WriteLine(item + " is included");
}

Open in new window

0
 
bmoabcCommented:
You can also return the resuts of a simple SQL if your table contents are unique records

SELECT table.[myTableContents]
FROM table
WHERE ((("sentence" Like "*" & table.[myTableContents] & "*")=True));

This will provide all the records send it to an array or another query, whatever you need...
0
 
meredithfAuthor Commented:
Thanks miketob for the idea.  It works.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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