0

I have string, for example

var string = 'This is my string. Lorem ipsum. Lorem ipsum.'.

This text, however, may be different. My question is how, using JavaScript/jQuery, could I make a new line after every dot in this string so that each sentence starts in a new line ?
Thanks for help.

1
  • 1
    wow, no effort made, and three answers so far Commented Mar 22, 2018 at 21:25

3 Answers 3

1
string.split(".").join(".\n")

Probably.

Sign up to request clarification or add additional context in comments.

Comments

0

Using regex:

var string = 'This is my string. Lorem ipsum. Lorem ipsum.'
console.log(string.replace(/\./g, '.\n'))

6 Comments

@Stphane can you elaborate your statement?
You replace the dot instead of just adding a newline.
@Stphane: The thing about the escapes is not true for JS.
I dont want to delete dots, just make linebreak after dot.
@Pat can you see carefully?
|
0
var string = 'This is my string. Lorem ipsum. Lorem ipsum.';
string.split(".").join("<br>");

this what you mean ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.