Determine the similarity between two characters and determine the two characters

Source: Internet
Author: User

Determine the similarity between two characters and determine the two characters

# Region determine the similarity between two characters
// Formula: l = q/(q + r + s );
Private string Similarity (string a, string B)
{

String a1 = "";
String b1 = "";

// Eliminate duplicates
For (int I = 0; I <a. Length; I ++)
{
String emtpy = a. Substring (I, 1). ToString ();
If (a1.Length = 0)
{
A1 = emtpy;
}
If (a1.IndexOf (emtpy, 0) <0)
{
A1 + = emtpy;
}
}
// Eliminate duplicates
For (int I = 0; I <B. Length; I ++)
{
String emtpy = B. Substring (I, 1). ToString ();
If (b1.Length = 0)
{
B1 = emtpy;
}
If (b1.IndexOf (emtpy, 0) <0)
{
B1 + = emtpy;
}
}

// Calculate similarity
If (a1.Length> = b1.Length)
{
Int q = 0;
For (int I = 0; I <b1.Length; I ++)
{
For (int j = 0; j <a1.Length; j ++)
{
If (b1.Substring (I, 1). ToString () = a1.Substring (j, 1). ToString ())
{
Q + = 1;
}

}
}
System. Globalization. NumberFormatInfo provider = new System. Globalization. NumberFormatInfo ();
Provider. PercentDecimalDigits = 2; // number of decimal places reserved.
Provider. PercentPositivePattern = 1; // Where is the percent sign.
Double result = (double) q/(a1.Length + b1.Length-q); // be sure to use the double type.
Return result. ToString ("P", provider );
}
Else
{
Int q = 0;
For (int I = 0; I <a1.Length; I ++)
{
For (int j = 0; j <b1.Length; j ++)
{
If (a1.Substring (I, 1). ToString () = b1.Substring (j, 1). ToString ())
{
Q + = 1;
}

}
}
System. Globalization. NumberFormatInfo provider = new System. Globalization. NumberFormatInfo ();
Provider. PercentDecimalDigits = 2; // number of decimal places reserved.
Provider. PercentPositivePattern = 1; // Where is the percent sign.
Double result = (double) q/(a1.Length + b1.Length-q); // be sure to use the double type.
Return result. ToString ("P", provider );

 

}



}
# Endregion

 

Load http://blog.sina.com.cn/s/blog_5f254b8a0100t4hy.html

 

Reference: http://www.360doc.com/content/09/0201/10/96202_2430832.shtml

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.