score:10

Accepted answer

You can use string.Replace which has an overload specifically for this.

var newString = oldString.Replace("foo", string.Empty);

This takes your oldString, finds all occurrences of "foo" and removes them.

score:5

This would work

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

Is that not correct?

score:4

Use extension methods:

public static class StringExtensions
{

    public static string RemoveOccurences(this string s, string occurence)
    {

         return s.Replace(occurence, "");    
    }

}

usage:

string s = "Remove all appearances of this and that and those";
s.RemoveOccurences("th");

Related Articles