Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xxl007/11122662 to your computer and use it in GitHub Desktop.
Save xxl007/11122662 to your computer and use it in GitHub Desktop.
Extracting a Substring from a String
// use the indexOf String method to locate start and end of substring to extract
// then extract the string with the substring String method
var sentence = "This is one sentence. Here comes the bit to copy: start .. end.";
var start = sentence.indexOf(":");
var end = sentence.indexOf(".", start+1); // start searching at position start+1 to avoid first dot
var list = sentence.substring(start+1, end);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment