• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Numeric Values
      • String Values
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • StringWriter Object
        • StringWriter Statement
        • StringWriter.clear Function
        • StringWriter.toString Function
        • StringWriter.write Function
        • StringWriter.writeEncoded Function
        • StringWriter.writeEncodedLine Function
        • StringWriter.writeLine Function
        • JSON Representation
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization 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 Statement

Format
StringWriter string_writer_name;
StringWriter string_writer_name(encoding_type);
StringWriter string_writer_name(report_name);
Description
The StringWriter statement creates a StringWriter, an incremental string builder, with the name string_writer_name. The StringWriter name must be unique and must contain only letters, numbers, or the underscore character. The name must begin with a letter. You can declare StringWriter objects globally in PROC GLOBAL or locally in functions or procedures.
If an encoding_type is specified in parentheses after the name of the object, text written to the StringWriter using the StringWriter.writeEncoded and StringWriter.writeEncodedLine functions will be encoded for that type. Any encoding type supported by the encode function is valid for a StringWriter, though the most common types are HTML or Markdown.
If a report_name is specified in parentheses after the name of the object, the StringWriter object wraps a templated report and assumes the encoding type used by the Report object.
You cannot specify an encoding_type or report_name when declaring a StringWriter as a user-defined function parameter because the StringWriter will assume the encoding type of the object passed to the function as an argument.
Example 1
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
Example 2
function AddToStringWriter(StringWriter sw)
    sw.
writeLine("<** Hello, **>");
    sw.
writeEncodedLine("<** World! **>");
end;

// the result based on different encoding types is shown:

StringWriter sw;                // <** Hello, **>
AddToStringWriter(sw);          // <** World! **>

StringWriter sw_html(HTML);     // <** Hello, **>
AddToStringWriter(sw_html);     // &lt;** World! **&gt;<br>

StringWriter sw_md(Markdown);   // <** Hello, **>
AddToStringWriter(sw_md);       //  &lt;\*\* World\! \*\*&gt;<br>
See also: StringWriter Object