• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • CSPro Program Structure
      • Programming Standards
      • Change Code Properties
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
        • Compiler Mode
        • Variables
        • Alias Statement
        • User-Defined Functions
        • Array Object
        • Audio Object
        • Case Object
        • Document Object
        • File Object
        • Freq Object
        • Geometry Object
        • HashMap Object
        • Image Object
        • List Object
        • Map Object
        • Pff Object
        • StringWriter Object
        • SystemApp Object
        • ValueSet Object
      • Procedural Sections
      • Logic
      • Language Elements
      • JavaScript Use in CSPro
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

StringWriter Object

Overview
A StringWriter is a CSPro logic object that supports building strings incrementally. Several write functions exist that add to the object's string buffer, either by writing text directly or by writing encoded text. Using a StringWriter is simpler, and more efficient, than concatenating many strings together.
The Report object, referring to a templated report, is a kind of StringWriter, and QSF, the special name used to write to question text, is also a kind of StringWriter.
Functionality
A StringWriter is a CSPro logic object and the following functions can be called via dot notation:
FunctionDescription
clearClears the contents of the string buffer, resetting the buffer to a blank string.
toStringReturns the current contents of the string buffer.
writeWrites text to the string buffer without encoding.
writeEncodedWrites text to the string buffer with encoding.
writeEncodedLineWrites text and a newline to the string buffer with encoding.
writeLineWrites text and a newline to the string buffer without encoding.
 
getLabelReturns the symbol's label.
getNameReturns the symbol's name.
getJsonReturns the symbol's metadata and value represented in JSON.
getValueJsonReturns the symbol's value represented in JSON.
setValueFromJsonModifies the symbol based on a JSON representation of the value.
Assignments
When a StringWriter, or a Report or QSF, is used as an argument to a user-defined function, it is passed by reference. The StringWriter parameter will assume the encoding type of the object passed to the function as an argument.
Conversions
StringWriter objects can be converted to and from JSON strings.
Example
StringWriter sw;

do numeric ctr = 1 while ctr <= 3
    sw.
writeLine("Random number #%d: %d", ctr, random(0, 100));
enddo;

// the result may look like:
errmsg("%s", sw.toString()); // Random number #1: 71
                             // Random number #2: 89
                             // Random number #3: 55
See also: String Statement, Templated Reports