How to get common values from two string in C# or Sql Server.

Posted by Jitendrasoft09 under Visual Studio on 3/28/2013 | Points: 10 | Views : 1350 | Status : [Member] [MVP] | Replies : 1
If i have two string with two values, how to get the common values in sql server, condition is below-
string str1= "/23/2/55/44/";
string str2= "/2/55/67/8/99/"

result of common value- "/2/55/".

Jitendra Kumar
If my post helps you, plz mark as an answer.



Responses

Posted by: Jayakumars on: 3/28/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

//Try this Code
string str1= "/23/2/55/44/";
string str2 = "/2/55/67/8/99/";
string st3 = "";
st3 = str1 + str2;
int strsp = str1.Split('/').Length;
int strsp1 = str2.Split('/').Length;
string Tot = "";

for (int i = 0; i <= strsp - 1; i++)
{
string str12 = str1.Split('/')[i];
for (int j = 0; j <= strsp1-1; j++)
{
string str13 = str2.Split('/')[j];
if (str12 == str13)
{
Tot += str12;
}
}
}

Response.Write(Tot);

Mark as Answer if its helpful to you

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

Login to post response