Linq or string filter
I need a filter in a row that takes another row as a parameter, scans the first row and removes all its manifestations.
+3
Peter17
source
share3 answers
You can use string.Replace , which has overload specifically for this.
var newString = oldString.Replace("foo", string.Empty);
This takes your oldString, finds all occurrences of "foo" and removes them.
+10
Joshua rodgers
source
shareIt will work
var s = "string";
s = s.Replace("st", string.Empty);
// s == "ring";
Is this wrong?
+5
James hugs
source
shareUse extension methods:
public static class StringExtensions
{
public static string RemoveOccurences(this string s, string occurence)
{
return s.Replace(occurence, "");
}
}
using:
string s = "Remove all appearances of this and that and those";
s.RemoveOccurences("th");
+4
Aliostad
source
share