Pre-recorded question

Question #11
In JavaScript, how to check whether a string contains a carriage return?
Answer

The following checks whether a string contains a line break (\n o r \r) :

var str = "abc \n def";
if (/\r|\n/.exec(str)) {
	// Do something, the string contains a line break

}

4 events in history
Question by Alphonsio 04/29/2020 at 06:12:38 PM
In JavaScript, how to check whether a string contains a carriage return?
Answer by Alphonsio 04/29/2020 at 06:11:22 PM

The following checks whether a string contains a line break (\n o r \r) :

var str = "abc \n def";
if (/\r|\n/.exec(str)) {
	// Do something, the string contains a line break

}

Answer by Alphonsio 04/29/2020 at 06:01:30 PM

The following check whether a string contains a line break (\n o r \r) :

var str = "abc \n def";
if (/\r|\n/.exec(str)) {
	// Do something, the string contains a line break

}

Question by Alphonsio 04/29/2020 at 05:59:50 PM
In JavaScript, how to check whether a string contains a line break?
# ID Query URL Count

Icons proudly provided by Friconix.