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

  • Home
  • SEARCH
  • 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 7419089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:59:58+00:00 2026-05-29T07:59:58+00:00

This is a problem from the CodingBat website. I am pasting the problem first

  • 0

This is a problem from the CodingBat website. I am pasting the problem first and discussing my efforts after that:

Given two strings, base and remove, return a version of the base string where all instances of the remove string have been removed (not case sensitive). You may assume that the remove string is length 1 or more. Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x".

withoutString("Hello there", "llo") → "He there"
withoutString("Hello there", "e") → "Hllo thr"
withoutString("Hello there", "x") → "Hello there"

This is what I wrote so far:

public String withoutString(String base, String remove) {

   int len_b=base.length();
   int len_r = remove.length();
   String result="";

   if(len_b<1 || len_r<1)
   return "";

   for (int i =0;i<=len_b-len_r;i++)
   {
      if(base.substring(i,i+len_r).equals(remove))
      {
        i=i+len_r-1;
      }

      else
      { 
        result=result+base.substring(i,i+1);
      }  
   } 

   if(!(base.substring(len_b-len_r+1, len_b).equals(remove)))
   result=result+base.substring(len_b-len_r+1, len_b);

return result;
}

This passes all the test cases except for the ones where the removal of the string should be case-insensitive.

For example: withoutString("This is a FISH", "IS") → "Th a FH"

My code gives me "This is a FH" as I haven’t handled case sensitivity in my code. I know that with Regex this could be done in one line. I am more interested in knowing if there is a way to handle these kinds of test cases in my present code.
Also, please let me know if my code could be made more efficient/elegant.

  • 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-29T07:59:59+00:00Added an answer on May 29, 2026 at 7:59 am

    String has an equalsIgnoreCase(String s) method.

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

Sidebar

Related Questions

I got this problem from an interview with Microsoft. Given an array of random
This problem is really confusing me; we're given two integers A , B ,
I am facing this problem from last month. First i was able to get
I may be approaching this problem from the wrong angle but what I'm thinking
This problem follows on from a previous question . When I run the following
This problem is baffling me: BEGIN; INSERT INTO sub_users(user_id, email) SELECT user_id FROM users
Continuing my problem from yesterday, the Silverlight datagrid I have from this issue is
I'm running into this problem when trying to call a SOAP Web Service from
I am completely stumped at the nature of this problem. We export data from
Expanding this question on how I learnt to pass from problem description to code

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.