I have manage to detect a line break in a string, but have can i remove it properly so in string would be only left "First Line"
var str = "First Line"
+"\nSecond Text Line";
var res = /\r|\n/.exec(str);
console.log(res);
I have manage to detect a line break in a string, but have can i remove it properly so in string would be only left "First Line"
var str = "First Line"
+"\nSecond Text Line";
var res = /\r|\n/.exec(str);
console.log(res);
There are several ways, but if you may have \r
or \n
, I'd probably use replace
with a regex:
str = str.replace(/(?:\r|\n).*$/, '');
use regex:
var str = "First Line" + "\n Second Text Line";
var line = str.replace(/(?:\r|\n).*$/, '');
console.log(line);
split string using a "\n" as a delimeter and then join the string back together
var strings = str.split("\n");
var finalstr =strings[0];