Search algorithm PLEASE HELP !!!

Hello

I need an algorithm for comparing 2 strings. IT must function like "LIKE" method in SQL.

Can anyone help me on this ?

I think it must be done with regular expresion, but i have no ideea how.

For example:

"Hello everybody in here, the java Forum" MUST mach with "everybody in here forum"

Is this possible ?

Thankx

[367 byte] By [JKodera] at [2007-10-3 6:18:38]
# 1
Help me out. I don't know SQL. How does LIKE work? How can you replicate its behavior without a description of what that behavior is?
marlin314a at 2007-7-15 1:03:31 > top of Java-index,Other Topics,Algorithms...
# 2

> Hello

> I need an algorithm for comparing 2 strings. IT must

> function like "LIKE" method in SQL.

> Can anyone help me on this ?

> I think it must be done with regular expresion, but i

> have no ideea how.

AFAIK, the SQL 'like' operator has two wildcards, % and _. These can be mapped to regexes fairly easily, though, its not the only way to get this behavior.

> For example:

>

> "Hello everybody in here, the java Forum" MUST mach

> with "everybody in here forum"

I don't think this should match. You need the wildcards % and _ in your pattern...

> Is this possible ?

RadcliffePikea at 2007-7-15 1:03:31 > top of Java-index,Other Topics,Algorithms...
# 3

Easy!

Try this:

1. Split the search string into an array

2. Make a 'for loop' that looks to see if all are found or else escapes at first non match and returns false;

3. Check to see if true or false;

String match = "Hello everybody in here, the java Forum";

String input = "everybody in here forum";

String[] fields = input.split(" ");

boolean matches = true;

loop:

for(String s : fields){

if( !s.equal(s)){

matches = false;

break loop;

}

}

System.out.println("Is [" + input + "] LIKE [" + match + "] = " + matches);

This is probably much faster than using a regular expression and works best on short target strings.

Wildfirea at 2007-7-15 1:03:31 > top of Java-index,Other Topics,Algorithms...