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
SurekaSureka 

How to get substring of a output text in visualforce?

Hi All, I am using the below format to retrive the feild label: However I need to remove the last 3 characters of the label during display. Any Idea? Thanks
Shailesh DeshpandeShailesh Deshpande

hi,

you cannot use sustring on page...you will have to do that in your controller and then render the value...

other option is to use javascript functions(substr) to do so..

 

 

Thanks,

Shailesh. P. Deshpande

SurekaSureka
Hi Shailesh, Thank you for the reply.
Pradeep_NavatarPradeep_Navatar

You can use visual force  function "LEFT" or 'RIGHT' for this purpose :

 

Command

Description

Use

LEFT

Returns the specified number of characters from the beginning of a text string.

LEFT(text, num_chars) and replace text with the field or expression you want returned; replace num_chars  with the number of characters from the left you want returned.

RIGHT

Returns the specified number of characters from the end of a text string.

RIGHT(text, num_chars) and replace text with the field or expression you want returned; replace num_chars  with the number of characters from the right you want returned.

SurekaSureka
Hi Pradeep, Thank you for the reply. I am currently using "" to get the field label. Could you please give a sample syntax of using LEFT or RIGHT functions here? Thanks
SurekaSureka
I am currently using Output Text - to get the field label. Could you please give a sample syntax of using LEFT or RIGHT functions here? Thanks
Pradeep_NavatarPradeep_Navatar

It will be something like this :

 

<apex:page >
<apex:outputText value="{!LEFT('GoodMorning',4)}"></apex:outputText>
<apex:outputText value="{!RIGHT('GoodMorning',7)}"></apex:outputText>
</apex:page>

 

 

Marvin BonifacioMarvin Bonifacio

Thank you very much for this! This worked for me! :catvery-happy:

Chris_PerezChris_Perez

John AlwanJohn Alwan
Was just playing around with this and this is what worked for me.
Thanks for the insights.

            <apex:column headerValue="Expiration Date"  >
                <apex:outputText value="{!left(Lease.ExpirationDate,10)}" />
            </apex:column> 
Manthri VamsyManthri Vamsy
Thanks for the Solution @Pradeep_Navatar..!! 
It saved my day..!!
Christopher MilnerChristopher Milner

Trying to get a visual force page that returns cases (similar to the stock related list). I would like the subject to pull in but be truncated so especially long subjects do not shove the rest of the information off the page.

<div class="Subject">
  <apex:column styleClass="gridcell">
     <apex:facet name="header">Subject</apex:facet>
     <apex:outputText value="{!LEFT(case.Subject,76)}"></apex:outputText>,
  </apex:column>

This seems to work halfway well, however it is forcing a comma at the end of every single subject line that is 75 characters or fewer.
User-added image

Is there a way to 1) remove the comma at the end of each line and 2) add a "..." to the end of only subject values that exceed that limit? i.e. if the subject is fewer than 75 characters, it just displays the subject as is. If the subject is longer than 75 characters, it displays "characterlimit+...".
Christopher MilnerChristopher Milner
Resolved issue 1 as I had an extra comma at the end of the output text tag. Any assistance with issue 2 would be great if anyone has any guidance!