+ Start a Discussion
michaellatideasmichaellatideas 

Outputing a String to a Minimum Width

Hopefully this is an easy question.  I'd rather not have to dive into and code something at the Apex level for this.

 

I'd like to be able to output a string into a fixed width field when I use apex:outputText

 

I'd like to output it and say that if the string I'm outputting is less than a specific width, it should be padded out enough to match that width.

 

I can't really use a table in this case, unfortunately.

 

Any good ideas?

JeremyKraybillJeremyKraybill

There is almost always a more elegant solution using HTML & CSS for this type of problem, but assuming you have a more legitimate reason for doing this than just missing the green-screen old world, you can achieve what you need by doing something like this:

 

{!row.Text_Field__c + IF(len(row.Text_Field__c) < 2, " ", "") + IF(len(row.Text_Field__c) < 3, " ", "")}

Just repeat that formula until you get to the length you need.

 

HTH

 

Jeremy Kraybill

Austin, TX

 

michaellatideasmichaellatideas

Thanks.  Yes, part of the problem is that an HTML table or some nice CSS won't quite do the job given some other pieces of the puzzle.