Click here to Skip to main content
15,896,154 members
Home / Discussions / C#
   

C#

 
GeneralRe: Quick bit field question Pin
Mike Dimmick5-Jul-04 13:38
Mike Dimmick5-Jul-04 13:38 
GeneralRe: Quick bit field question Pin
benglish725-Jul-04 15:12
benglish725-Jul-04 15:12 
QuestionSQL Security Hole - am I vulnerable? Pin
Ian Bowler5-Jul-04 13:04
Ian Bowler5-Jul-04 13:04 
AnswerRe: SQL Security Hole - am I vulnerable? Pin
Mike Dimmick5-Jul-04 13:33
Mike Dimmick5-Jul-04 13:33 
GeneralRe: SQL Security Hole - am I vulnerable? Pin
Ian Bowler5-Jul-04 21:32
Ian Bowler5-Jul-04 21:32 
GeneralRe: SQL Security Hole - am I vulnerable? Pin
Colin Angus Mackay5-Jul-04 23:25
Colin Angus Mackay5-Jul-04 23:25 
Generalcomparison of two strings - how to get a score Pin
rlacatus5-Jul-04 12:34
rlacatus5-Jul-04 12:34 
GeneralRe: comparison of two strings - how to get a score Pin
rlacatus6-Jul-04 11:30
rlacatus6-Jul-04 11:30 
Hi folks,

Well, there seems to be little interest in the subject. Either that, or I wasn't very clear on what I wanted - or, few people had what to say of instructive on the matter. No matter the case, in case anyone is looking for a solution, here is what I've found:

There is, amongst other things, a good article online (a university paper in fact) that is easy to understand, to the point, and free to download from here:

http://arxiv.org/abs/cs.DS/0112022 (See PostScript or PDF link at bottom)

Anyway, based on this very good document, I've written a C# function to compare two strings, and give a percentage on how close the strings are to one another as such:


// Found http://arxiv.org/abs/cs.DS/0112022
// July 6, 2004

// From: qi xiao yang
// Date (v1): Fri, 21 Dec 2001 05:58:12 GMT (250kb)
// Date (revised v2): Tue, 25 Dec 2001 21:29:22 GMT (294kb)

// Faster Algorithm of String Comparison
// Authors: Qi Xiao Yang, Sung Sam Yuan, Lu Chun, Li Zhao, Sun Peng

private double StringCompareValue(string str1, string str2)
{
string strX, strY; // smaller and bigger of the strings, respectively
double val; // return value
int window, wPos; // window width and position
double SSNC = 0; // value used to calculate return in the end

// get smaller & bigger strings sorted out
// also, perform lower case conversion
if(str1.Length < str2.Length)
{
strX = str1.ToLower();
strY = str2.ToLower();
}
else
{
strX = str2.ToLower();
strY = str1.ToLower();
}

// initialize
window = strX.Length;
wPos = 0;

// while the window exists and the smallest string exists
while(window > 0 && strX.Length > 0)
{
// while the window doesn't overlap the end of the string
while((wPos + window) <= strX.Length)
{
// get string to compare to
string comparer = strX.Substring(wPos, window);
// start comparison point at zero
int cPos = 0;

// loop through second string to get all possible comparisons
while(cPos + window <= strY.Length)
{
// if comparisons match
if(comparer == strY.Substring(cPos, window))
{
// update SSNC Value
SSNC += Math.Pow((2 * window), 2);

// remove "used characters"
strY = strY.Remove(cPos, window);
strX = strX.Remove(wPos, window);

// force window position to stay same place (moved forward again at end of loop)
wPos--;;

// continue search with next window position
break;
}

// move right on longer string
cPos++;
}

// move right on shorter string
wPos++;
}

// decrease window size - reset to beginning of string
window--;
wPos = 0;
}

// get percentage value
val = Math.Sqrt( (SSNC) / Math.Pow( (str1.Length + str2.Length) , 2) ) * 100;

return val;

}




If anyone finds this useful, you're free to use for any purpose, with the condition that the original article is referenced. I take no credit for the code, it is simply typing out the C# equivalent of the pseudo-code found in the article, which in turn is found free for use online.

If you have any comments, please post - I'm curious of your thoughts. Also, if there are any bugs in the code, let me know - I haven't tested too thoroughly.

All the best,

R
GeneralDataGrid current row Pin
Christian Graus5-Jul-04 11:13
protectorChristian Graus5-Jul-04 11:13 
GeneralRe: DataGrid current row Pin
Christian Graus5-Jul-04 12:14
protectorChristian Graus5-Jul-04 12:14 
GeneralRe: DataGrid current row Pin
Heath Stewart5-Jul-04 18:08
protectorHeath Stewart5-Jul-04 18:08 
GeneralRe: DataGrid current row Pin
sreejith ss nair6-Jul-04 2:03
sreejith ss nair6-Jul-04 2:03 
GeneralAccessing Data with Web Forms Pin
Ian Bowler5-Jul-04 10:38
Ian Bowler5-Jul-04 10:38 
GeneralRe: Accessing Data with Web Forms Pin
Colin Angus Mackay5-Jul-04 11:13
Colin Angus Mackay5-Jul-04 11:13 
GeneralRe: Accessing Data with Web Forms Pin
Ian Bowler5-Jul-04 11:41
Ian Bowler5-Jul-04 11:41 
GeneralRe: Accessing Data with Web Forms Pin
Colin Angus Mackay5-Jul-04 11:56
Colin Angus Mackay5-Jul-04 11:56 
GeneralRe: Accessing Data with Web Forms Pin
Ian Bowler5-Jul-04 12:03
Ian Bowler5-Jul-04 12:03 
GeneralRe: Accessing Data with Web Forms Pin
Colin Angus Mackay5-Jul-04 12:22
Colin Angus Mackay5-Jul-04 12:22 
GeneralRe: Accessing Data with Web Forms Pin
Ian Bowler5-Jul-04 12:46
Ian Bowler5-Jul-04 12:46 
GeneralRe: Accessing Data with Web Forms Pin
Colin Angus Mackay5-Jul-04 13:03
Colin Angus Mackay5-Jul-04 13:03 
GeneralRe: Accessing Data with Web Forms Pin
Heath Stewart5-Jul-04 18:06
protectorHeath Stewart5-Jul-04 18:06 
GeneralSearch object in hierarchy object (class) Pin
god4k5-Jul-04 5:58
god4k5-Jul-04 5:58 
GeneralRe: Search object in hierarchy object (class) Pin
Heath Stewart5-Jul-04 10:08
protectorHeath Stewart5-Jul-04 10:08 
QuestionHow to compare MemoryStream? Pin
god4k5-Jul-04 5:57
god4k5-Jul-04 5:57 
AnswerRe: How to compare MemoryStream? Pin
Heath Stewart5-Jul-04 10:01
protectorHeath Stewart5-Jul-04 10:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.