Searching string..
-
Hello! Is there any algorithm for something like this: bool Matches(string text, string search) {..} Which allows me to search in the following way.. Lets say text = "hello how are you blah blah k thanks bye" Searching for "'hello how'" would return true (Notice the ') Searching for "'hello howdy'" would return false Searchinf for "hoy hello are" would return true (Notice there are not ' in this search) Well, you get the idea ( I hope so) Its like google search but, of course simplier
-
Hello! Is there any algorithm for something like this: bool Matches(string text, string search) {..} Which allows me to search in the following way.. Lets say text = "hello how are you blah blah k thanks bye" Searching for "'hello how'" would return true (Notice the ') Searching for "'hello howdy'" would return false Searchinf for "hoy hello are" would return true (Notice there are not ' in this search) Well, you get the idea ( I hope so) Its like google search but, of course simplier
Hi, this should do it (pseudo-code):
stringlist list=new stringlist
string[] searches=search.split('\'') // split on quotes
bool quoted=false
foreach string s in searches {
if (quoted) list.add(s)
else foreach string s2 in s.split(' ') list.add(s2) // split on spaces
quoted=!quoted
}
foreach string s in list if !text.contains(s) return false
return truePS: it could be handled without the list, just test right away instead of adding to list... :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
modified on Friday, April 24, 2009 11:38 PM
-
Hello! Is there any algorithm for something like this: bool Matches(string text, string search) {..} Which allows me to search in the following way.. Lets say text = "hello how are you blah blah k thanks bye" Searching for "'hello how'" would return true (Notice the ') Searching for "'hello howdy'" would return false Searchinf for "hoy hello are" would return true (Notice there are not ' in this search) Well, you get the idea ( I hope so) Its like google search but, of course simplier
You could also try to solve that with a suffix tree or array approach. This is, up to my knowledge, usually the fastest solution. Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
-
Hello! Is there any algorithm for something like this: bool Matches(string text, string search) {..} Which allows me to search in the following way.. Lets say text = "hello how are you blah blah k thanks bye" Searching for "'hello how'" would return true (Notice the ') Searching for "'hello howdy'" would return false Searchinf for "hoy hello are" would return true (Notice there are not ' in this search) Well, you get the idea ( I hope so) Its like google search but, of course simplier
In c++: #include <string.h> char *strstr( const char *str1, const char *str2 ); The function strstr() returns a pointer to the first occurrence of str2 in str1, or NULL if no match is found. If the length of str2 is zero, then strstr() will simply return str1. For example, the following code checks for the existence of one string within another string: char* str1 = "this is a string of characters"; char* str2 = "a string"; char* result = strstr( str1, str2 ); if( result == NULL ) printf( "Could not find '%s' in '%s'\n", str2, str1 ); else printf( "Found a substring: '%s'\n", result ); :laugh: