473,395 Members | 2,436 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,395 software developers and data experts.

Partially compare two strings

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.

Apr 11 '07 #1
5 2855
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"co*******@gmail.com" wrote:
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.

Apr 11 '07 #2
How about string.EndsWith?
Correct me, if I have not understood the problem statement correctly.

Kalpesh

On Apr 11, 3:21 pm, coding...@gmail.com wrote:
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.

Apr 11 '07 #3
co*******@gmail.com wrote:
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
Apr 12 '07 #4
How about string.EndsWith?

Kalpesh

On Apr 11, 3:21 pm, coding...@gmail.com wrote:
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.

Apr 12 '07 #5
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.

On Apr 11, 9:21 pm, coding...@gmail.com wrote:
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.

Apr 13 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: J.W. | last post by:
How do I compare strings in javascript? The "==" double equals or "!=" doesn't seem to work in this case. I'm sure string comparison has been explained before but searching Google didn't find...
3
by: Drew | last post by:
Hello - I am a converted VB programmer. What I am trying to do it compare two strings in an if statement. The problem is that when I use string.compare it always returns a negative 1. I have...
19
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I...
11
by: balakrishnan.dinesh | last post by:
hi frnds, Im having two 20digit numbers, But while comparing those it is giiving wrong ouput in javascript. for example here is my code, my secanrio is , ~ If first 20 digit number is...
3
by: Twinkle | last post by:
HI there i want to compare between two strings char by char.every strings having a word document.first string name is strFileName and second string name is strFilename1. i want to compare...
50
by: titan nyquist | last post by:
I wish to compare two structs via == but it does not compile. I can overload and create my own == but am I missing something that c# already has implemented? ~titan
2
by: Peter Proost | last post by:
Hi group, I want to compare path strings in order to sort them, assuming I have got: "a.txt" "dir1\c.txt" "e.txt" "dir1\d.txt" When I compare them using "e.text" would be greater than...
3
by: lweunice | last post by:
hi, I need to partially sort a struct vector and I have written a function that looks like: void AxisSort(int start, int end){ sort(prims.begin() + start, prims.begin() +...
11
by: Tony | last post by:
Hello! Below I have two different ways to test if the instance tb.Text contains the string "Programmer" So which one to use is it just a matter of taste ? Or could it be some advantage to one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.