Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Windows. Forms;
Namespace string Similarity
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
* ****** Void button#click (object sender, EventArgs e)
{
String str1 = textbox1.text;
String str2 = textbox2.text;
Label3.text = get_semblance_by_2words (str1, str2 );
}
Public static string get_semblance_by_2words (string word1, string word2)
{
Int Re = 0;
Int maxlength;
Int I, L;
List <string> tb1 = new List <string> ();
List <string> tb2 = new List <string> ();
I = 0;
L = 1;
MaxLength = word1.Length;
If (word1.Length <word2.Length)
MaxLength = word2.Length;
While (l <= word1.Length)
{
While (I <word1.length-1)
{
If (I + L> word1.length)
Break;
Tb1.add (word1.substring (I, L ));
I ++;
}
I = 0;
L ++;
}
I = 0;
L = 1;
While (l <= word2.Length)
{
While (I <word2.Length-1)
{
If (I + l> word2.Length)
Break;
Tb2.Add (word2.Substring (I, l ));
I ++;
}
I = 0;
L ++;
}
Foreach (string subStr in tb1)
{
Int tempRe = 0;
If (tb2.Contains (subStr ))
{
TempRe = subStr. Length * 100/maxLength;
If (tempRe> re)
Re = tempRe;
If (tempRe = 100)
Break;
}
}
Return re. ToString () + "% ";
}
}
}
Source code download