Skip to content

Instantly share code, notes, and snippets.

@lahmatiy
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lahmatiy/271f3227d9eba0437530 to your computer and use it in GitHub Desktop.
Save lahmatiy/271f3227d9eba0437530 to your computer and use it in GitHub Desktop.
function getRange(str, start, end){
var lines = str
.split('\n')
.slice(start.line - 1, end.line);
return lines
.concat(lines.pop().substr(0, end.column))
.join('\n')
.substr(start.column - 1);
}
var str = '12345678\n222222\n3333';
console.log(getRange(str, { line: 1, column: 3 }, { line: 1, column: 5 }));
// 345
console.log(getRange(str, { line: 1, column: 3 }, { line: 2, column: 3 }));
// 345\n222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment