please help me to solve the question i cant able to get the logic behind this question

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"
gnanagowthaman sankarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
The logic is simple.  Take two strings, one is the source string, the second is the string that contains the portion to remove.  Your task is to remove the second string from the first string.  For the non-overlapping instances, if your source string is "xxx" and you remove "xx", you should be left with "x".

So you will need a mechanism to loop over the first string and compare the characters with the second string taking into account that the second string is 1 or more characters, you may need to loop over the second string once you find a character in the source string that matches the character in the second string.

-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gnanagowthaman sankarAuthor Commented:
thank you very much it_saige
0
CEHJCommented:
FYI you can do it in one line with one method of String
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

it_saigeDeveloperCommented:
True, they can, but something tells me that their instructor is looking for a loop based implementation.

-saige-
0
awking00Commented:
Take a look at the replaceAll method for strings.
0
krakatoaCommented:
Do you plan on closing any of your other similar open questions, or are you going to ask your way merrily through the entire Codingbat range?
0
gnanagowthaman sankarAuthor Commented:
Sir how to close the question sir
0
krakatoaCommented:
ARE you trying to troll us?
0
gnanagowthaman sankarAuthor Commented:
No am new to this forums honestly don't know how to close it
0
krakatoaCommented:
You were already given a link to that procedure in one of your earlier questions.
0
gnanagowthaman sankarAuthor Commented:
Sorry sir please give me the link sir
0
krakatoaCommented:
Err . . .
0
awking00Commented:
Why in the world would codingbat provide such a ridiculous method of looping through a string, comparing characters and length as a solution when the solution is as simple as -
public String withoutString(String str, String remove) {
  return str.removeAll(remove,"");
}
???
0
krakatoaCommented:
Probably because there is no such method as removeAll. But maybe also because replaceAll doesn't work either.
0
awking00Commented:
krakata,thanks for pointing out my error. Forgive me for the use of removeAll when I meant replaceAll, but that does seem to work. In what case does it not?
0
krakatoaCommented:
Well, you can try it yourself, and satisfy yourself that the code is input as you intended rather than triangulate the matter through me as I may not have understood your intention.
0
awking00Commented:
I did try it before I even posted my comment with the following results:
replaceAll("Hello there","llo") ==> "He there"
replaceAll("Hello there", "e") ==> "Hllo thr"
replaceAll("Hello there", "x") ==> "Hello there"
replaceAll("xxx","xx") ==> "x"
0
CEHJCommented:
Hint folks: the codingbat problem is case-insensitive
0
krakatoaCommented:
Those are not the results I get. Your code obtains the following afaics :

withoutString results
1
krakatoaCommented:
Hint folks: the codingbat problem is case-insensitive

CEHJ sir,

Don't quite follow you - - - codingbat supplies the String and the element to remove. I can't see anywhere the cases are exposed to us?

Unless you mean that replaceAll uses regex . . . but that doesn't really help, or does it?
0
awking00Commented:
Thanks, CEHJ. It always helps to read the question carefully. To make the replacement case insensitive, add the case regex insensitive prefix -
public String withoutString(String str, String remove) {
   return str.replaceAll("(?I)" + remove,"");
 }
0
awking00Commented:
Forgive EE's attempts at being helpful "(?I)" was meant to be "(?i)" with a lowercase letter i.
0
CEHJCommented:
... was meant to be "(?i)" with a lowercase letter i.
Yes, that was my solution as well ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.