• <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
      • 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
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
        • compare Function
        • compareNoCase Function
        • Concat Function
        • String Concatenation Operator
        • Edit Function
        • GetBuffer Function
        • Length Function
        • maketext Function
        • Message Formatting Options
        • Pos Function
        • PosChar Function
        • RegExMatch Function
        • Replace Function
        • StartsWith Function
        • Strip Function
        • ToLower Function
        • ToNumber Function
        • ToUpper Function
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization 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>

Replace Function

Format
s = replace(source_text, old_text, new_text);
Description
The replace function looks at source_text and replaces one or more instances of the substring old_text with the value in new_text. All arguments are string expressions and the replacement is case sensitive, meaning that "c" is recognized as different from "C".
Return Value
The function returns a new string with the replaced text.
Example 1
string example = "Robert Smith's son's name is Robert, Jr.";

example = 
replace(example, "Robert", "Bob");

// result: Bob Smith's son's name is Bob, Jr.
Example 2
function string GetFileUri(string local_filename)

   
// get the full path in case the filename is relative
    local_filename = Path.concat(local_filename);

   
// convert all backslashes to forward slashes
    local_filename = replace(local_filename, "\\", "/");

   
// encode the filename as a URI
    exit "file:///" + encode(URI, local_filename);

end;

// ...

string reports_css_uri = GetFileUri("../CSS/Reports.css");
html_file.
write("<link rel='stylesheet' type='text/css' href='%s'>", reports_css_uri);
See also: Encode Function, Pos Function