“Wymień nową linię TextArea w JavaScript” Kod odpowiedzi

JavaScript Zastąp linia Breaks na BR

function nl2br(str){
 return str.replace(/(?:\r\n|\r|\n)/g, '<br>');
}
var stringWithNewLines= `Well this is a
a very broken
sentance`;
var stringWithBrs=nl2br(stringWithNewLines);
// stringWithBrs= "Well this is a<br>a very <br>broken<br>sentance"
Grepper

JavaScript Usuń pęknięcia linii z ciągu

var stringWithLineBreaks = `
O boy 
I've got 
Breaks
`;
var stringWithoutLineBreaks = stringWithLineBreaks.replace(/(\r\n|\n|\r)/gm, "");//remove those line breaks
Grepper

Wymień nową linię TextArea w JavaScript

function nl2br(str){
 return str.replace(/(?:\r\n|\r|\n)/g, '<br>');
}
var stringWithNewLines= `Well this is a
a very broken
sentance`;
var stringWithBrs=nl2br(stringWithNewLines);
// stringWithBrs= "Well this is a<br>a very <br>broken<br>sentance"
Amused Addax

Odpowiedzi podobne do “Wymień nową linię TextArea w JavaScript”

Pytania podobne do “Wymień nową linię TextArea w JavaScript”

Więcej pokrewnych odpowiedzi na “Wymień nową linię TextArea w JavaScript” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu