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;
    }
}
  • you can use Split() function as well – HSdev Jan 23 '17 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 Jan 23 '17 at 13:08
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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.