• <Helps for GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Array Object
      • Audio Object
      • Barcode
      • File Object
      • Freq Object
      • HashMap 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
        • 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
    • Appendix
  • <Helps for CSEntry>
  • <Helps for CSBatch>
  • <Helps for CSTab>
  • <Helps for DataViewer>
  • <Helps for TextView>
  • <Helps for TblView>
  • <Helps for TRSWin>
  • <Helps for CSDeploy>
  • <Helps for CSPack>
  • <Helps for CSFreq>
  • <Helps for CSSort>
  • <Helps for CSExport>
  • <Helps for CSReFmt>
  • <Helps for CSDiff>
  • <Helps for CSConcat>
  • <Helps for TRSSetup>
  • <Helps for ParadataViewer>
  • <Helps for ParadataConcat>
  • <Helps for CSIndex>
  • <Helps for Excel2CSPro>
  • <Helps for 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 slashes 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