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
amar kumar10amar kumar10 

Break string and display as 2

Hi,
i have assigned a string to a variable and want to display the string in 2 lines.
expected result:

User-added image
Sample code

VF Code
-----------------------------------------------------------
<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;
    }

}
Any help would pe appreciated
Best Answer chosen by amar kumar10
EldonEldon
Hi Amar,

replace your VF and Apex with the below codes,


VF
<apex:page controller="BreakString1Controller">
    <apex:outputtext escape="false" value="{!str2}"/>
</apex:page>

APEX
public class BreakString1Controller {

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

    public BreakString1Controller (){
        str2 = str1;
    }

}


Regards
 

All Answers

EldonEldon
Hi Amar,

replace your VF and Apex with the below codes,


VF
<apex:page controller="BreakString1Controller">
    <apex:outputtext escape="false" value="{!str2}"/>
</apex:page>

APEX
public class BreakString1Controller {

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

    public BreakString1Controller (){
        str2 = str1;
    }

}


Regards
 
This was selected as the best answer
Muzammil BajariaMuzammil Bajaria
Hi amar,
Try using this and let me know 

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

Hi Eldon,

Its working

thanks for your help.

amar kumar10amar kumar10

Hi,
If i use {!Str2} in the VF page in place of outputtext then there is any option to get my expected result.

Ramssf70Ramssf70
Hi amar,
you can use <apex:outputlabel>{!str2}</apex:outputlabel>.if you use this also you will ge same result