Comparing two Strings without using string functions for Job Seekers

Sakthi.Singaravel
Posted by Sakthi.Singaravel under C# category on | Points: 40 | Views : 1385
Here the code for comparing two strings in c# .net:

Code :


private void button1_Click(object sender, EventArgs e)
{
string str1 = "new";
string str2 = "new";
int count1 = 0;
int count2 = 0;
bool flag = true;
foreach (char c in str1)
count1++;
foreach (char c in str2)
count2++;
if (count1 == count2)
{
for (int j=0;j<=count2 -1;j++)
{
if (str1[j]==str2[j])
{}
else
flag =false;
}
}
if (flag==true )
MessageBox.Show("Strings matched");
else
MessageBox.Show ("Strings Mismatch");
}

Comments or Responses

Login to post response