BASEER HAIDER JAFRI
BASEER HAIDER JAFRI

Reputation: 949

break line issue in javaScript?

I am receiving a comments from service. If I get this comment "hello world" it is printing as it is but when I receive Comments like this "hello

world" then I am receiving nothing I write a function for it but it also doesn't work

function NextLineFix(Call) {

        return Call.replace("\n", '<br>');
    }

Can any body help please....!

Upvotes: 0

Views: 106

Answers (3)

jerjer
jerjer

Reputation: 8766

try this:

function NextLineFix(Call) {    
    return Call.replace(/[\r\n]/gi, '<br/>');
}

Upvotes: 2

Igor Franc&#233;
Igor Franc&#233;

Reputation: 328

Perhaps you also have carriage return characters in the string ('\r')? Does this work better for your issue:

Call.replace("\r", "").replace("\n", "<br/>") ?

Upvotes: 2

lloydom
lloydom

Reputation: 387

Try it with \r\n instead of \n and then do the replace , see if that helps

Upvotes: 0

Related Questions