0

i have assigned a string to a variable and want to display the string in 2 lines. expected result: enter image description here

Sample Code

Vf Page

<apex:page controller="BreakString1Controller">

    <apex:outputText value="{!str2}"></apex:outputText>

</apex:page>

Controller code

public class BreakString1Controller {

    public string str1 = 'Quick brown fox jumps \n '+' <br/>'+' over the lazy dog';
    public string str2 {get; set;}

    public BreakString1Controller (){
        str2 = str1;
    }
}
2
  • you can use Split() function as well
    – HSdev
    Commented Jan 23, 2017 at 6:52
  • You should just use CSS and word wrapping to achieve this objective, which you can ask about on Stack Overflow.
    – Adrian Larson
    Commented Jan 23, 2017 at 13:08

1 Answer 1

2


Use Following

<apex:outputText escape="false" value="{!str2}"></apex:outputText>

Controller:

public class BreakString1Controller {

   public string str1 = 'Quick brown fox jumps <br/>'+' over the lazy dog';
   public string str2 {get; set;}

   public BreakString1Controller (){
     str2 = str1;
   }
 }


OutPut :

enter image description here

escape="false":
If the String you want to display contains HTML or XML-reserved characters, you need to use escape="false" so that Your Chars and other characters are not interpretted as VF page markup.

Also please refer to following question before using escape = false
How to avoid security risks with escape="False" in output tags

Thanks,
Nachiket

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .