Compare a string in C#.net

Naraayanan
Posted by Naraayanan under C# category on | Points: 40 | Views : 1507
       private string  CompareText(string fValue,string svalue)
{
string formHeading = fValue;
string userSearch = svalue ;
string constring = string.Empty;
string comstring = string.Empty;
string[] formHeadingWords;
string[] userSearchWords;
formHeadingWords = System.Text.RegularExpressions.Regex.Split(formHeading, @"\W");
userSearchWords = System.Text.RegularExpressions.Regex.Split(userSearch, @"\W");
int cntFarray = formHeadingWords.Length;
int cntSarray = userSearchWords.Length;
if (cntSarray > cntFarray)
{
foreach (string _str in userSearchWords)
{
if (!formHeading.Contains(_str))
{
comstring = _str;
}
if (comstring.Trim() != constring.Trim())
{
constring = constring + " " + comstring;
}

}
}
else
{
foreach (string _str in formHeadingWords)
{
if (!userSearch.Contains(_str))
{
comstring = _str;
}
if (comstring.Trim() != constring.Trim())
{
constring = constring + " " + comstring;
}

}
}

return constring;

}


Call this function in the Button Click event
string str = CompareText(textBox1.Text,textBox2.Text );
label1.Text = str;
label1.ForeColor = Color.Red;

Comments or Responses

Posted by: T.saravanan on: 2/5/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi Narayanan,

Could you give a little bit explanation about your code? Its really useful to the users.
Posted by: Naraayanan on: 2/5/2012 Level:Starter | Status: [Member] | Points: 10
Hi ,
Thanks for your reply.

Login to post response