I am trying to process a string before displaying it in a visualforce page. What I need to do is remove any quotation marks in the text field before I use it to assemble a link path. The following code works - it removes any 'S' characters from the string. However when I substitute in a '"' which is what I want to remove, it is interpreted as ending the value argument and the page won't save. I thought I could escape it out with '\"' or '\\"' and I also tried '&quot' but none of those options worked.

        <td class="value">
            <apex:outputText value="{!SUBSTITUTE(Work_Order__c.Drawing_Path__c, 'S', '')}" />

I know that I could do my processing at another step (either with a formula field or an apex trigger) but I was really hoping to do it here as I have other areas built around the string still having the quotes in it. Is there any way to solve this problem in the VisualForce page only?


This works in my developer org:

<apex:page standardController="Account">
        <apex:inputField value="{!Account.Name}" />
        <apex:outputText value="{!SUBSTITUTE(Account.Name,'\"','')}" />

Apparently, syntax highlighting can't seem to figure it out, but it should compile just fine (press Enter in the demo page to see the resulting output).

  • So it is! I feel pretty silly for just being thrown off by the syntax highlighting. With tho backslashes I got an actual error in the 'problems' section about the expression being unbalanced, but if I let it update, it goes away with one. Thanks! – Ethan48 Jan 29 '16 at 22:29

Do you have a controller?

public static String parseString(String theString, String checkFor, String replaceWith)
    String result;

    result = thestring.replaceAll(checkFor, replaceWith);

    return result;
  • I am using the standard controller, but I see how if I switched to a custom one that would work. – Ethan48 Jan 29 '16 at 22:21
  • How is this any different than simply calling replaceAll directly on the original string, without a particularly verbose function call? – sfdcfox Jan 29 '16 at 22:22
  • @sfdcfox, I'm not sure why I did it.. I think I had a reason, but I forget why now – EricSSH Jan 29 '16 at 22:25
  • If I hard coded the " in the apex, rather than taking checkFor as an argument, then it would have solved the problem since I know how to escape things in apex. – Ethan48 Jan 29 '16 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.