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");
Source: stackoverflow.com
Related Articles
- Linq filter List<string> where it contains a string value from another List<string>
- LINQ Source Code Available
- How do i use filter in linq against non string fields?
- Linq or string filter
- Filter a string using LINQ
- creating Linq to sqlite dbml from DbLinq source code
- linq to entities changing database connection string in code
- How to filter by enum from string in LINQ C#
- source code for LINQ 101 samples
- How to filter string in C# using linq to exclude all letters and numbers?
- Filter list of entity objects by string child object property using Linq Lambda
- Creating a dynamic EF filter that builds a LINQ Where equals/contains statement for any string entity property
- Filter a generic list with a dynamic condition string with linq
- Filter a Generic list using LINQ using a PropertyName as a string literal - Using dynamics
- LINQ : filter multiple string values - partial match - not full match as in multiple online examples
- Filter a Dictionary by value where value is a list of string using LINQ
- List or Array of String Contain specific word in Html Source Code
- Simple linq question: How to filter a source afterwards?
- LINQ filter string with value string
- how to translate a linq expression into sql string use c# code
- c# Linq or code to extract groups from a single list of source data
- How to convert a string to C# code in the SELECT of C# LINQ
- Filter LINQ To Entities (EF Core) query by List of HashSet of String and Enum
- Trying to filter only digits in string array using LINQ
- I want to convert a filter string from given string(sql server supported filter) format to linq acceptable filter format
- How do I convert a linq expression to Azure Table Filter String in .NET Core?
- Linq Statement Returns Max Lengths of all Columns Filter Other Than String Type
- How Filter Binding Source Connected To linq Query
- Suggestions on how to optimize code for ordering by string in linq
- Convert string[] to int[] in one line of code using LINQ
- bug in linq Contains statement - is there a fix or workaround?
- Creating a C# LINQ optional Join extension
- LinQ sum group by between using Lambda
- Sorting a List of Lists by the amount of intergers of the same type they contain
- Keep throwing an error and I do not know why
- Entity Framework GroupBy to Sql Generation
- How can I make this LINQ search method handle more than two terms?
- left outer join 3 tables in linq to sql
- How to find (and remove) a nested object from a List
- Avoid Repeating Group by Linq in C#
- How can i compare the variable var with the enum in C#
- Sorting a list in .Net by one field, then another
- The most elegant and efficient way of calculate union of a collection of IEnumerable
- How to sort a List using a nested Dictionary in Linq C#?
- How to use mod function for linq to ms access?
- How to select specific columns in one-to-one relationship table along with few direct columns in Entity Framework Fluent API
- How to handle null values with where clause in LINQ?
- Multiple join with Lambda Expression
- What return value to use to match two different kinds of Types
- How to call a specific method on an object after creating it via its constructor using reflection in .NET?