How can I add special characters to a string?

The need occasionally arises to embed a double-quote or other characters inside a text string in an InduSoft Web Studio project.  Since defining text strings are normally done by putting the string to be saved within double-quotes, it is not simply a matter of putting a double-quote or other non-printable characters inside double-quotes (“”").  If you attempt it, an error will be returned.

The most common method for embedding a double-quote character in a text string is by concatenation.  This method will work in virtually all cases:

$sExampleStringTag = “This is a double-quote character: ” + $Asc2Str(34) + ” .”

String Result: This is a double-quote character: ” .

Using an ASCII Character Table (Web search for “ASCII Character Table”), it is possible to find any ASCII character, even unprintable ones, and embed them into a text string using concatenation. Using the decimal value of the ASCII Code, use the function ASC2Str() and enter the value inside the parentheses.

  • If you're using VBScript, you can use the ordinary Chr(x) notation to concatenate a single character into a string. Chr(34) is a double-quote, Chr(39) is a single-quote, Chr(13) is a carriage return, etc.

    For example, I wanted to put some text inside single quotes in a Message Box, so my syntax was like this:

    [code] MBChoice = MsgBox("Click OK to confirm creation of the new Custom Group "+Chr(39)+NewGroupName+Chr(39),vbOKCancel) [/code]
  • You can also just use two double-quotes inside a quoted string as shown below,
    $sExampleStringTag = "This is a double-quote character: ""."

    When VBScript sees two consecutive double quote characters in a quoted string, then it is interpreted as a single double-quote character.

    Larry Combs
    InduSoft Technical Support Team