KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to write double quotes within a string value
PRODUCT: 4D | VERSION: 11 | PLATFORM: Mac & Win
Published On: August 9, 2011

Sometmes you may find yourself in a situation where you need to assign a value that includes quotes to a string variable, for example when using a command with parameters to be used with LAUNCH EXTERNAL PROCESS. Consider the following command line:

mp3convert.exe -file="test.mp3" -convert_to="Wave" -bits="16" -freq="44100"


The above command uses quotes in its parameters; so in order to assign that to a string variable, special care must be taken for the quotes.
  1. The quotes can be escaped with a backslash like this:

    C_TEXT($myString)
    $myString:="mp3convert.exe -file=\"test.mp3\" -convert_to=\"Wave\" -bits=\"16\" -freq=\"44100\""


  2. The quote can be concatenating in to the string value using the Char command with the character code of the quote:

    C_TEXT($myString)
    $myString:="mp3convert.exe -file="+Char(34)+"test.mp3"+Char(34)+" -convert_to="+Char(34)+"Wave"+Char(34)+" -bits="+Char(34)+"16"+Char(34)+" -freq="+Char(34)+"44100"+Char(34)


  3. The constant for the double quote can also be used like so:

    C_TEXT($myString)
    $myString:="mp3convert.exe -file="+Char(Double quote)+"test.mp3"+Char(Double quote)+" -convert_to="+Char(Double quote)+"Wave"+Char(Double quote)+" -bits="+Char(Double quote)+"16"+Char(Double quote)+" -freq="+Char(Double quote)+"44100"+Char(Double quote)