• <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>

Pos Function

Format
i = pos(substring, source_string);
Description
The pos function searches for a grouping of characters, represented in a substring, within a source_string. The function returns the beginning position of the first occurrence of the substring. Both arguments are string expressions, and they are case sensitive, meaning that "children" is recognized as different from "CHILDREN".
If using an alpha string or dictionary item, be aware that searching for a space character can lead to the function finding one at the end of your string. You may want to strip alphanumeric variables before searching for spaces.
Return Value
The function returns the position of the first occurrence of the substring, or if the substring is not found, the function returns 0.
Examples
VALUE = pos("L", "FOR THE CHILDREN");   // VALUE will be 12; this is where the
                                        // substring (the letter "L") occurs in the
                                        // source string ("FOR THE CHILDREN")

VALUE = 
pos("DRE", "CHILDREN");         // VALUE will be 5; this is where the
                                        // substring ("DRE") occurs in the source string

VALUE = 
pos("DCN", "CHILDREN");         // VALUE will be 0; the substring ("DCN") does
                                        // not occur in the source string
See also: PosChar Function, StartsWith Function, Replace Function, IsChecked Function