16,004,479 members
See more:
Plz Help I got two string values
string a= "1,3,2,4,5";
b = "3,4";
c = a-b;
c = "1,2,5";
remove second string value from first string
and I want the result as "1,2,5"
Posted
Updated 11-Sep-14 1:14am
v5
ErBhati 11-Sep-14 6:34am
Bh@gyesh 11-Sep-14 6:36am
Can you please more elaborate on this?
[no name] 11-Sep-14 6:39am
Okay so remove the "3,4" from the first string.

## Solution 1

C#
```var s1 = "1,2,3,4,5";
var s2 = "3,4";
s1 = s1.Replace(s2, string.Empty).Replace(",,",",");```

You are using the "Replace" method twice here, the first removes the second string, the second looks for double , and replaces it with a single ,

George Jonsson 11-Sep-14 7:18am
In this case what happens if s2 is changed to "2,3,4"?
Pheonyx 11-Sep-14 7:19am
You'd get 1,5 :-)
George Jonsson 11-Sep-14 8:20am
You are absolutely right.

## Solution 5

Sounds like Homework. Try this

C#
```char[] delimiterChars = { ',' };

string a = "1,3,2,4,5";
string b = "3,4";

string[] A = a.Split(delimiterChars);
string[] B = b.Split(delimiterChars);

List<string> C = A.Except<string>(B).ToList();
string c = string.Join(",", C);```

Matt T Heffron 11-Sep-14 12:03pm
+5

## Solution 4

try below code

C#
```for (int i = 0; i < s1.Length; i++)
{
int count = 0;
if (s1[i] != ',')
{

for (int j = 0; j < s2.Length; j++)
{
if (s1[i].ToString() == s2[j].ToString())
{
count++;
}
}
if (count == 0)
s3 += s1[i].ToString() + ',';
}
}
s3.Remove(s3.Length - 1);
```

## Solution 6

Try this Code..

C#
```string s1 = "1,2,3,4,5";
string s2="2,3";
var res1 = s1.Split(',');
var res2 = s2.Split(',');
string res = "";
for(int i=0;i<res1.count();i++)>
{
for(int j=0;j<res2.count();>
{
if (res1[i] == res2[j])
{
break;
}
else
{
if ((j == (res2.Count() - 1)))
{

res = res + res1[i].ToString() + ",";
}
}
}
}
```

v2