fork(2) download
  1. class FnR {
  2.  
  3. public static String withoutString(String base, String remove) {
  4.  
  5. final String lcbase = base.toLowerCase();
  6. final String lcremove = remove.toLowerCase();
  7. int find = 0;
  8. int previous = 0;
  9. StringBuilder result = new StringBuilder(base.length());
  10. while ((find = lcbase.indexOf(lcremove, previous)) >= 0) {
  11. result.append(base.substring(previous, find));
  12. previous = find + remove.length();
  13. }
  14. result.append(base.substring(previous));
  15. return result.toString();
  16.  
  17. }
  18.  
  19. public static void main(String[] args) {
  20. String[][] inputs = {
  21. { "Hello there", "llo" },
  22. { "Hello there", "e" },
  23. { "Hello there", "x" },
  24. };
  25. for (String[] d : inputs) {
  26. System.out.printf("'%s' from '%s' remove '%s'\n", withoutString(d[0], d[1]), d[0], d[1]);
  27. }
  28. }
  29. }
  30.  
Success #stdin #stdout 0.11s 320256KB
stdin
Standard input is empty
stdout
'He there' from 'Hello there' remove 'llo'
'Hllo thr' from 'Hello there' remove 'e'
'Hello there' from 'Hello there' remove 'x'