Maximilian
Lifer
Spent the better part of an hour trying to solve what seemed like a simple problem, its labelled as a hard problem but it didnt look all that tough:
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"
100 lines of code later and i still haven't got it :| Then i look at Strings methods and see a wonderful little method called replaceAll() 😡
base = base.replaceAll(remove, "");
//does basically what my 100 lines and while loops with lists arrays and the whole shebang failed to do.
Felt like sharing :awe:
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"
100 lines of code later and i still haven't got it :| Then i look at Strings methods and see a wonderful little method called replaceAll() 😡
base = base.replaceAll(remove, "");
//does basically what my 100 lines and while loops with lists arrays and the whole shebang failed to do.
Felt like sharing :awe: