Last active
August 29, 2015 14:14
-
-
Save lahmatiy/271f3227d9eba0437530 to your computer and use it in GitHub Desktop.
This file contains 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
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