• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • Data Requirements
      • CSPro Program Structure
      • Programming Standards
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
      • Procedural Sections
      • Logic
      • Language Elements
        • Version
        • Delimiters
        • Comments
        • Preprocessor
        • Variables and Constants
        • Expressions
        • Operators
          • Operators
          • String Comparisons
          • In Operator
          • Has Operator
          • If and Only If Operator
          • Operator Precedence
          • And/Or Truth Table
        • Files
        • Miscellaneous
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and 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>

String Comparisons

There are a variety of ways to compare two strings in CSPro logic. However, the way that strings are compared depends on the logic version.
The original routine to compare strings right-pads strings with space (blank) characters as necessary so that the length of the string does not factor into the comparison. This applies to comparisons using:
  • String comparison functions: compare and compareNoCase
  • String operators: =, <>, <, <=, >=, >, in, and has
  • Statements that can compare strings: recode and when
  • Other functions: List.removeIn
With logic version CSPro 8.0+, strings are compared without any padding. This is desirable for most strings, but when comparing strings against alphanumeric dictionary items, which are right-padded to match the dictionary item length, you will likely want to use the strip function when comparing strings; for example:
if BIRD_NAME = "Bobolink" then        // Original logic version
if strip(BIRD_NAME) = "Bobolink" then // CSPro 8.0+ logic version
Comparison Results
The following table shows the results of string operations that are not impacted by padding and lead to the same result regardless of logic version.
Left StringRight String comparecompareNoCase=<><<=>=>
"abc""abc"00truefalsefalsetruetruefalse
 
"abc""ABC"10falsetruefalsefalsetruetrue
"ABC""abc"-10falsetruetruetruefalsefalse
 
"abc""abcd"-1-1falsetruetruetruefalsefalse
"abcd""abc"11falsetruefalsefalsetruetrue
 
"abc""xyz"-1-1falsetruetruetruefalsefalse
"xyz""abc"11falsetruefalsefalsetruetrue
The following table shows the results of string operations that are impacted by padding based on the logic version.
Left StringRight StringLogic Version comparecompareNoCase=<><<=>=>
"abc""abc   "Original00truefalsefalsetruetruefalse
 CSPro 8.0+-1-1falsetruetruetruefalsefalse
 
"abc   ""abc"Original00truefalsefalsetruetruefalse
 CSPro 8.0+11falsetruefalsefalsetruetrue
See also: Logic Version