Click here to Skip to main content
15,671,318 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Suppose I have a list of value like this:

Below is first sentences that I print out I'm giving the output in the paragraph.
Lorem Ipsum is simply dummy text of the printing and typesetting industry.\n

(and below is second sentences that I want to print out it in the paragraf again)
Contrary to popular belief, Lorem Ipsum is not simply random text.

As you see there is special characters,which is called '\n' at the end of the first sentences. I want to do some business logic that when user click on the enter button I want to print out that sentences another paragraf, but I couldn't it.

What I have tried:

is there any solution to do this?
Updated 8-Nov-22 8:06am
Richard MacCutchan 8-Nov-22 14:08pm    
The "\n" character is the end of line marker. But you have not explained exactly what code you are using to process this, or what you expect the user interactions to be.
vor_zakon_developer 8-Nov-22 14:10pm    
String output = <your string="" here="">
String indented = output.replaceAll("(?m)^", "\t");

I am using in the above code but it doesn't work
[no name] 8-Nov-22 14:16pm    
You have to use different pattern:

"(?m)\w+(\s+|\s*\.\s*)" - something like this should work.

1 solution

If it's about HTML and Java or JavaScript, then probably you have to use "<br>"-tag which stands for the new line on page item.
Share this answer
vor_zakon_developer 8-Nov-22 14:00pm    
I am using handle bars file template generator and data comes from front end side like payload list of value, and I put that list of value to the {{listOfValue}} tags. That is why I asked the question.
[no name] 8-Nov-22 14:06pm    
I assume you have to replace each '\n' with tag with additional constraint for each of the extracted sentences from the input data.

In general your problem is of parsing and regular expressions.
[no name] 8-Nov-22 14:19pm    
Your pattern is as I've understood should look like this:

Richard Deeming 9-Nov-22 6:12am    
You need to HTML-encode any HTML tags outside of a <pre> block if you want them to show up properly.
[no name] 9-Nov-22 6:13am    
Ok, thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900