Created
April 20, 2014 19:19
-
-
Save xxl007/11122662 to your computer and use it in GitHub Desktop.
Extracting a Substring from a String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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