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
source share
3 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
source

It will work

var s = "string";
s = s.Replace("st", string.Empty);
// s == "ring";

Is this wrong?

+5
source

Use 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
source

Source: https://habr.com/ru/post/1796506/


All Articles