Skip to content

Instantly share code, notes, and snippets.

@jarek-foksa
Created July 2, 2011 16:35
Show Gist options
  • Save jarek-foksa/1061121 to your computer and use it in GitHub Desktop.
Save jarek-foksa/1061121 to your computer and use it in GitHub Desktop.
/**
* Trim sting to the part between prefix and suffix
*/
String.prototype.between = function(prefix, suffix) {
var string = this;
var i = string.indexOf(prefix);
if (i >= 0) {
string = string.substring(i + prefix.length);
}
else {
return '';
}
if (suffix) {
i = string.indexOf(suffix);
if (i >= 0) {
string = string.substring(0, i);
}
else {
return '';
}
}
return string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment