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

New line character in APEX



I have String array with some values. I want to print those values line by line.


Also let me know how can we use escape characters in APEX.


Please share your suggestions.




Cory CowgillCory Cowgill

APEX is simliar to Java (In fact, you can think of it as a wrapper on top of Java) in syntax and language constructs.


For your example, you can use '\n' to insert a linebreak in a string.


ArrayList<String> vals = new ArrayList<String>('A','B','C');

String allStrings = '';

for(String val : vals)


    allStrings = allStrings + val +  '\n' ;




You can escape characters with the '\' symbol.

Yves Asselin 3Yves Asselin 3
Actually, thanks to my co-worker Denis Roy, I was able to find the solution I believe everyone is looking for! First, in your attribute string, add this to where you want your break   &lt;br/&gt;   and then when your reference it, wrap it with aura:unescapedHtml.


At the top, add this attribute:
<aura:attribute name="title" type="String" default="Connect, talk shop and swap success stories,&lt;br/&gt; pics and trade secrets with members of the community."/>

In your code, add this to your attribute reference like so: 
<aura:unescapedHtml value="{!v.title}" />
chandravijay metkarchandravijay metkar
@Cory Cowgill 
\n it's not working in the console.