Skip to content

Instantly share code, notes, and snippets.

@Songbird0
Created August 14, 2016 22:41
Show Gist options
  • Save Songbird0/ba5aa134248c697cafb131cef3ffa32e to your computer and use it in GitHub Desktop.
Save Songbird0/ba5aa134248c697cafb131cef3ffa32e to your computer and use it in GitHub Desktop.
function sliceAt(initial_string, target) {
var index = initial_string.indexOf(target);
if (index !== -1) {
switch (index) {
case 0: return initial_string.substring(index + target.length);
case (initial_string.length - 1): return initial_string.substring(index, target.length - 1);
}
var first_part = '';
var second_part = '';
first_part = initial_string.substring(0, index);
second_part = initial_string.substring(index + 1);
return "" + first_part + second_part;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment