You need to sign in to do that
Don't have an account?
SSRS2
Remove middle spaces
I want to get values with middle spaces but only show one space in output (Salesforce.com API version 19.0).
VF page:
<apex:page controller="TestSpace">
<apex:outputText value="A B"></apex:outputText><br/>
<apex:outputText >A C</apex:outputText><br/>
<apex:outputText value="{!fromController}"></apex:outputText><br/>
<apex:outputText >A E</apex:outputText><br/>
</apex:page>
Apex Class:
public class TestSpace {
public String getFromController() {
return 'A D';
}
}
Output:
A B //not expected
A C //not expected
A D //not expected
A E //ok
-Suresh
With style="white-space:pre;" could obtain the output with middle spaces.
-Suresh
All Answers
I'm slightly confused, as the output you have marked as unexpected has a single space between the first and second value, which I though was what you wanted.
Anyhow, this is a browser function - browsers collapse repeated whitespace into a single space. If you want multiple spaces, you have to use non-breaking spaces ( ) and tell the outputText component not to escape html by setting the escape attribute to false.
Can you explain a little more about what you are expecting to see?
Thanks Bob.
It's working with ' ' and escape ‘false’ but is it ok when application need to do security review.
-Suresh
I'm afraid I can't help with that. I don't see why the security review would worry about non-breaking spaces being unescaped. That said, if it opens up a way for malicious HTML to appear, I would expect it to be a problem.
With style="white-space:pre;" could obtain the output with middle spaces.
-Suresh