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 7500429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:10:54+00:00 2026-05-29T20:10:54+00:00

This is code from the book – Programming Interviews Exposed 2nd Edition – Pages

  • 0

This is code from the book – “Programming Interviews Exposed” 2nd Edition – Pages 78 & 79
– Remove Specified Characters Exercise (continued below)

void Main()
{
    string se = "I_am_the_string_to_modify";
    string re = "amthe";

    Console.WriteLine(se);
    Console.WriteLine(re);

    char[] s=se.ToCharArray();
    char[] r=re.ToCharArray();
    bool[] flags=new bool[128];

    int len=s.Length;
    int src,dst;

    for(src=0;src<len;++src)
    {
        Console.Write(r[src]+",");
        flags[r[src]]=true;
    }

    src=0;
    dst=0;

    while(src<len)
    {
        if(!flags[(int)s[src]])
        {
            s[dst++]=s[src];
        }
        ++src;
    }
    string str=new string(s,0,dst);
    Console.WriteLine(str);
}

If I try to run this I get IndexOutOfRangeException: Index was outside the bounds of the array. due to line 18. The author is trying to do the same kind of thing on line 26.

The point is to create a look-up array that identifies the chars that are to be removed. I have a working version of this but I did not use the nested array indexes.

Is there a way that this should be working? I don’t see how the nested arrays would ever work.

  • 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-29T20:10:56+00:00Added an answer on May 29, 2026 at 8:10 pm

    Your problem is that you’re indexing into r (a 5-element array) but looping to s.Length (25).

    Change line 12 to int len=r.Length; and line 20 to len=s.Length;.

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

Sidebar

Related Questions

I'm trying to understand this code from Deitels 5th edition c book. If I'm
Just copy this code from perl cook book 2nd ed pp. 796 it returns:
I'm trying to compile this piece of code from the book The C Programming
hI, I'm trying to get this code from Larry Nyhoff's book to compile in
I have the following piece of code from a book. There is this function
in the book i'm learning from i came across this code snippit: while (i
I study this code from some book: #include <pthread.h> #include <stdio.h> /* Parameters to
This code is from the agile web development with rails book.. I don't understand
This is from some sample code from a book // On launch, create a
I believe there's a typo on this code snippet extracted from Stroustup's book, at

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.