Showing posts with label extension method. Show all posts
Showing posts with label extension method. Show all posts

2009-07-29

string.Remove(string toReplace)

/// <summary>

/// Alias for 'ReplaceWithEmpty'

/// </summary>

public static string Remove(this string arg, string toReplace)

{

    return arg.ReplaceWithEmpty(toReplace);

}

2009-07-21

string.ReplaceWithEmpty(string toReplace)

[Test]
public void ShouldReplaceWithEmpty()
{
const string arg = "This is a string";

Assert.AreEqual("This is a", arg.ReplaceWithEmpty(" string"));
}

public static string ReplaceWithEmpty(this string arg, string toReplace)
{
return arg.Replace(toReplace, string.Empty);
}