How to compare to strings string2 compare to string 1 in c# without using string function

Posted by Sekar.C under C# on 3/28/2012 | Points: 10 | Views : 1400 | Status : [Member] | Replies : 6
hi,
How to compare to strings string2 compare to string 1 in c# without using string function
String 1=" Welcome all"
String 2="com "

Regards
Sekar.c

Regards
Sekar.c



Responses

Posted by: Sksamantaray on: 3/28/2012 [Member] Silver | Points: 25

Up
0
Down
can use loop and compare character by character when mismatch break the loop and show appropriate message

Thanks,
Sanjay

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/5/2012 [Member] Silver | Points: 25

Up
0
Down
compare to strings string2 compare to string 1 in c# without using string function


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");
}

Regards,
Singaravel M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/6/2012 [Member] Silver | Points: 25

Up
0
Down
Are u got solution..?

Regards,
Singaravel M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/7/2012 [Member] Silver | Points: 25

Up
0
Down
Are u got solution using the code..?

Regards,
Singaravel M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 4/9/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Check this Code
      string str1 = "Welcome all";

string str2 = "com ";
int count1 = 0;
int count2 = 0;
bool flag = true;
foreach (char c in str1)
count1++;
foreach (char c in str2)
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");


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/9/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Lakshmi Naraayanan,

i think u are posted duplicate post (See the Second reply for this Query)...

Regards,
Singaravel M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response