Say for example I have the following string:
var testString = ‘Hello, world’;
And I want to call the following methods:
var newString = testString.Replace(‘Hello’, ”).Replace(‘world’, ”);
Is there some code construct that simplifies this, so that I only have to specify the Replace method once, and can specify a bunch of parameters to pass to it in one go?
Create a function to which you pass the
Stringand aDictionary(String, String). Iterate over each item in the Dictionary andInputString.Replace(DictionaryEntry.Key, DictionaryEntry.Value). Return the string with the replaced values.But I’d just do
.Replace.Replaceif it’s only 2 times…