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 : 1512 | Status : [Member] | Replies : 2
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: 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

Login to post response