Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5979173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:37:19+00:00 2026-05-22T21:37:19+00:00

I have the following extension method (which is invalid and does not compile ATM):

  • 0

I have the following extension method (which is invalid and does not compile ATM):

    public static string Strip( this string str, char[] charsToStrip )
    {
        foreach( char c in charsToStrip )
        {
            str.Replace( c, "" );
        }

        return str;
    }

The str.Replace() call needs to invoke the ‘char’ overload of Replace(), however using this overload I’m not sure what to pass into the 2nd parameter to tell it to replace with “nothing”.

The goal of this function is to iterate each character in the charsToStrip variable and remove all instances of that character in the source string, str.

Also if my function is reinventing the wheel, let me know. I’m using .NET 3.5

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:37:20+00:00Added an answer on May 22, 2026 at 9:37 pm

    Try:

    str = str.Replace(c.ToString(), String.Empty);
    

    Note that instances of string are immutable. As such, you need to assign the result of String.Replace otherwise the result is lost.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following extension method public static class ListExtensions { public static IEnumerable<T>
i have the following linq extension method, which returns an IEnumerable. This means, that
I have an extension method with the following signature (in BuildServerExtensions class):: public static
I have created an extension method called AddGZip which looks like the following: public
I have an extension method that looks like the following: //[MethodImpl(MethodImplOptions.NoOptimization)] public static IEnumerable<char>
I have an extension method defined like so: public static TSource MaxBy<TSource, TResult>(this IEnumerable<TSource>
I have the following structure. public class ToolSettings { public string Extension { get;
This may not be possible without writing some crazy extension method which I do
I have the following extension method which asserts that a property (Id) contains a
I am trying to compile the following code: public static void RequireOrPermanentRedirect<T>(this System.Web.UI.Page page,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.