asked on
string strWithMinusOne = "-1,2,3,-1,-1,105,-1,2,-1,-1" ;
//After removing all the '-1' I should have the following string
string result = "2,3,105,2"
I tried something like this:public string RemoveAllOccurencesOfMinusOne(string strWithMinusOne, char s)
{
// strWithMinusOne = "-1,2,3,-1,-1,105,-1,2,-1,-1"
string resultString = string.Empty;
foreach (char c in strWithMinusOne)
{
if (c == '-1')
{
index1 = strWithMinusOne.IndexOf(c);
resultString = strWithMinusOne.Remove(index1, 1);
}
}
return resultString;
}
It didn't seem to work and I don't know how to handle the commas (,) ...
Could someone give a hint?
Thank you