Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,558,938
Community Members
 
Community Events
184
Community Groups

Remove end-of-line characters from a comment body

John Colosi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Apr 07, 2023

I want to remove end-of-line characters from a comment body. Things I tried:

  • comment.body.trim
    • trim doesn't remove end-of-line characters for whatever reason.
  • xmlEncode and other encodings
    • did not seem to encode the end-of-line characters so I could remove them
  • replaceAll(regex,string)
    • the regex is applied line-by-line, so trailing end-of-line characters get processed, but not removed

 

Ultimately I decided to use indexOf to get the first instance of an "\r" character. But in order to effectively remove them, I had to make sure at least one was there. So I ended with this solution.

  • comment.body.left(comment.body.concat("\r").indexOf("\r"))

This is obviously ugly. There should be a better way to remove end-of-line characters. Please help.

 

1 answer

1 vote
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Apr 07, 2023

Hi @John Colosi 

Have you tried to use split() on the newlines (effectively removing them) and then join() with the character of your choice to concatenate the text?

Depending on the source text, you may want to check for both newline and line feeds.

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer