I need to snip out a substring from a string data which has a line break or '\n' in it.
var mainString = "HERE IS THE BEGIN OF LINE
PRINT HERE IS END OF LINE";
Please find the code below which I tried:
<!DOCTYPE html>
<html>
<body>
<p>Click the button</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var mainString = "HERE IS THE BEGIN
OF LINE PRINT HERE IS END OF LINE";
var n = mainString.indexOf("OF LINE");
var str = "OF LINE";
var result = mainString.substr(n + str.length);
document.getElementById("demo").innerHTML = result;
}
</script>
</body>
</html>
If I gets the data as an input from a textarea, is it possible to implement the backtick idea? If not, is there any alternate solution? please help! Thanks in advance.