Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a line break at specific location in string

I have a doubt of how do I add a line breaker in a js string . The below is the code :

{ 
  "id": 7, 
  "last": 1, 
  "name": "Customer received Email to change the password/Received. And code that customer  hasn’t requested" 
},

I want a line break after password/Received. I want the desired output as

Customer received Email to change the password/Received.
And code that customer  hasn’t requested
like image 508
Sashi Verma Avatar asked Feb 04 '26 14:02

Sashi Verma


1 Answers

If you want to add the line break and cannot modify the origin of the text, then you could do something like this:

str = "Customer received Email to change the password/Received. And code that customer  hasn’t requested";
str.replace("password/Received. ","password/Received.\n");

Replace \n with <br/> if you want to output this in HTML.

like image 62
ColdIV Avatar answered Feb 06 '26 04:02

ColdIV