• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • Data Requirements
      • CSPro Program Structure
      • Programming Standards
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
      • Procedural Sections
      • Logic
      • Language Elements
        • Version
        • Delimiters
        • Comments
        • Preprocessor
        • Variables and Constants
          • Data Items
          • This Item ($)
          • Subscripts
          • Numbers
          • Boolean Values
          • Special Values
          • Refused Value
          • String Literals
          • Newline Handling
        • Expressions
        • Operators
        • Files
        • Miscellaneous
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

String Literals

A string literal is zero or more characters enclosed between a pair of double quotation marks ("...") or single quotation marks ('...'). In CSPro, string literals will appear in the text editor colored in magenta. Any spaces enclosed within the quotation marks are considered part of the string literal. Uppercase and lowercase letters may be used, and the string literal "a" is different than "A".
String literals are compiled differently based on an application's logic version.
Logic Version: Original
The original version of string literals does not allow for escape sequences. If you wish to have single quotation marks embedded within your string, you must use double quotation marks to enclose it, and vice versa. For example, this results in a compiler error:
myString = 'That's great!';
This would set myString to 'that' and the trailing 's great!' would be considered outside the string, and would therefore result in a compiler error. Thus, if you wanted to accomplish the above, you must write:
myString = "That's great!";
Similarly, if you wanted to embed double quotation marks within your string, you must write the string as follows:
myString = 'The chair is 23" high';
Escape Sequences (Logic Version: CSPro 8.0+)
With logic version CSPro 8.0+, escape sequences are processed. An escape sequence begins with a backslash character and is followed by a valid character. For example, using this logic version, the string above could be written as:
myString = 'That\'s great!';
The backspace before the single quotation mark indicates that the next character is a special character. In this case, the special character does not end the string literal, but instead places a single quotation mark into the string without terminating the string literal. Note that the text editor colors escape sequences slightly differently than the other characters in a string literal.
The following escape sequences are recognized by CSPro.
Escape SequenceDescription
\'single quotation mark
\"double quotation mark
\\backslash
\aaudible bell
\bbackspace
\fform feed
\nline feed
\rcarriage return
\thorizontal tab
\vvertical tab
The escape sequences used most frequently are for quotation marks (\' and \"), backslashes (\\), and newline characters (\n). When using double quotation marks to surround a string literal, it is not required to escape single quotation marks, and vice versa.
Here are some examples of string literals with escape sequences that are valid with logic version CSPro 8.0+:
// all display: "abc"
//              'xyz'
errmsg("\"abc\"\n\'xyz\'");
errmsg("\"abc\"\n'xyz'");
errmsg('\"abc\"\n\'xyz\'');
errmsg('"abc"\n\'xyz\'');
Verbatim String Literals (Logic Version: CSPro 8.0+)
When using string literals that contain many backslash characters, such as a Windows file path, it may be convenient to use a verbatim string literal (when using logic version CSPro 8.0+). To create a verbatim string literal, use an @ character, immediately followed by text surrounded by double quotation marks. For example, these two strings are identical:
 "C:\\Program Files (x86)\\CSPro 8.0\\html\\images\\cspro-logo-medium.png" // string literal
@"C:\Program Files (x86)\CSPro 8.0\html\images\cspro-logo-medium.png"      // verbatim string literal
Within a verbatim string literal, the only character that must be escaped is a double quotation mark, which is escaped as two subsequent quotation marks: "". For example:
// displays: The woman asked, "What is your favorite letter: a \ b \ c \ x \ y \ z?"
errmsg(@"The woman asked, ""What is your favorite letter: a \ b \ c \ x \ y \ z?""");
See also: String Comparisons, Logic Version