function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tf_ianrtf_ianr 

Convert carriage returns to html line-breaks in a long text field

If I'm binding a text field into a VisualForce page, whats a good way to convert the carriage returns in the text-field into HTML <br/> tags?

I can think of a few ways of doing it, but I'm wondering what the neatest way is.

This question is also at StackOverflow (with a bounty!) if you want to earn some StackOverflow points:

http://stackoverflow.com/questions/2525707/visualforce-convert-carriage-returns-to-html-line-breaks-in-a-long-text-field
Best Answer chosen by Admin (Salesforce Developers) 
tf_ianrtf_ianr

I eventually solved this by writing a load of code.

 

See my answer at StackOverflow for details.

All Answers

TehNrdTehNrd

Try this:

 

 

<apex:outputField value="{!case.Description}"/>

 

 Using output fields will maintain formatting automagically.

 

tf_ianrtf_ianr

I tried this and I couldn't get it to work.

When case.Description contains carriage returns, apex: outputField does not maintain the formatting.

tf_ianrtf_ianr

I eventually solved this by writing a load of code.

 

See my answer at StackOverflow for details.

This was selected as the best answer