Partially compare two strings

C

codingeek

I can't seem to find the right keywords to find the google to my
problem.

I need to find out if two strings have a partial match within each
other.

I am using it do to URL comparisons for an httpmodule I am writing.

For me, I want a regex or simple algorithm to make statements like
this true:

"~/Subfolder/Login.aspx" is like "localhost/Application/Subfolder/
Login.aspx"

I get "~/Subfolder/Login.aspx" from GetFormsAuthLoginUrl() and
"localhost/Application/Subfolder/Login.aspx" from
CurrentRequest.Url.AbsolutePath so both of these values will depend on
how developers setup forms authentication on websites.

I am sure I can find some kind of answer by doing a comparison of
Url.Segments or maybe a comparison on instrings starting at the last /
but I just found it intriguing I could not easily find a generic
string-like-string snippet on the web.
 
G

Guest

You probably want to look into something called the Levenshtein algorithm,
which basically comes up with a "distance" figure based on how many character
substitutions it takes to turn one string into the one you are comparing to.

If you look around, there's plenty of sample C# code implementing this and
similar "comparison" algorithms.
Peter
 
K

Kalpesh

How about string.EndsWith?
Correct me, if I have not understood the problem statement correctly.

Kalpesh
 
A

Alun Harford

I can't seem to find the right keywords to find the google to my
problem.

I need to find out if two strings have a partial match within each
other.

I am using it do to URL comparisons for an httpmodule I am writing.

For me, I want a regex or simple algorithm to make statements like
this true:

"~/Subfolder/Login.aspx" is like "localhost/Application/Subfolder/
Login.aspx"

I get "~/Subfolder/Login.aspx" from GetFormsAuthLoginUrl() and
"localhost/Application/Subfolder/Login.aspx" from
CurrentRequest.Url.AbsolutePath so both of these values will depend on
how developers setup forms authentication on websites.

I am sure I can find some kind of answer by doing a comparison of
Url.Segments or maybe a comparison on instrings starting at the last /
but I just found it intriguing I could not easily find a generic
string-like-string snippet on the web.

Well if you want a generic string-like-string method, you need something
like BLAST.

Alun Harford
 
A

atlaste

Two simple solutions from my part:
1. put all url's in a database and do a soundex or similar
2. implement the hunt-szymanski algorithm

The latter can be found from the (excellent) paper of "Graham A.
Stephen", called "string search". I'm sure it's online somewhere.

Cheers,
Stefan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top