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
Paul McMurrughPaul McMurrugh 

Change Font Size Based on Number of Characters

Hi all,

I would like to know if there is a Visualforce condition based on how many characters there are? I would like to make some text smaller if it goes over 30 characters in length.

Thanks!
Raj VakatiRaj Vakati
Use this type of code 
<div style="text-align:center;font-weight:bold; background-color:{!IF(rec.length ==20,'red', 'blue')}">
            <apex:outputText value="{!rec.name}"/>
        </div>
		Controller : - 
		public string getrec()
		
		}

 
Raj VakatiRaj Vakati
You can use style attribute from the visualforce tags . 
v varaprasadv varaprasad
Hi Paul,

please check once below code.
 
string accName = 'varaprasad';

if(accName.length() > 5){
    accName = accName.substring(0,5);
}
system.debug('==accName=='+accName);
Hope this helps,
please let me know in case you need any assistance.

Thanks
Varaprasad
Hemant_SoniHemant_Soni
Hi Paul McMurrugh,
I think you need to use javascript in your visualforce page.
for example:
var str = "Hello World!";
var n = str.length;

and you get length of string and you can make change according to length.
I think this may help you.
Thanks
Hemant