Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - = non-exact string comparison operator http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 =                   Non-exact string comparison operator
------------------------------------------------------------------------------
 Syntax
   cString1 = cString2

 Arguments
   cString1 is the left side character string to compare.

   cString2 is the right side character string to compare.

 Description
   The = operator performs a case-sensitive comparison of the two string
   operands according to the xBase language conventions.

   The operator respects the status of the internal flag controlled by the
   set exact command. When the exact flag is off, the two character strings
   are compared according to the following rules:

   - if cString2 is null, return .t.

   - if the length of cString1 is greater than the length of cString1,
     return .f.

   - if all characters in cString2 equal the corresponding characters in
     cString1, return .t.; otherwise return .f.

   When the exact flag is on, the two strings must match exactly for
   returning .t., except for trailing blanks.

 Example
   #define EXAMPLE_OPERATOR
   #include example.hdr

   /*
   String comparisons (when set exact is off) are performed by
   comparing single characters from left to right until the end
   of the string to the right of the relational oparator is reached.
   In the above example, the end will be reached before comparing
   the first pair of characters, giving .t. as result.
   */
   
   proc EmptyTest static
   vardef
      char cString
   enddef
   
   // with set exact on, a non-empty string does not appear to be empty
   // when using the = operator for comparison
   set exact on
   cString := "Germany"
   if cString = ""        // evaluates to .f.
      cString := "USA"
   endif
   ? cString              // prints Germany
   
   // with set exact off, a non-empty string appears to be empty
   // when using the = operator for comparison
   set exact off
   cString := "Germany"
   if cString = ""        // evaluates to .t.
      cString := "USA"
   endif
   ? cString              // prints USA
   
   // using the == operator excludes any confusion in string comparisons
   cString := "Germany"
   if cString == ""       // evaluates to .f., although set exact is still off
      cString := "USA"
   endif
   ? cString              // prints Germany
   endproc
   
   proc Test_926
   set exact off
   ? "David"        = ""             // prints .T.
   ? "David"        = "David Lowrey" // prints .F.
   ? "David"        = "David       " // prints .F.
   ? "David Lowrey" = "David"        // prints .T.
   ? "David       " = "David"        // prints .T.
   set exact on
   ? "David"        = ""             // prints .F.
   ? "David"        = "David Lowrey" // prints .F.
   ? "David"        = "David       " // prints .T.
   ? "David Lowrey" = "David"        // prints .F.
   ? "David       " = "David"        // prints .T.
   ?
   EmptyTest()
   endproc

   proc main
   Test_926()
   endproc

See Also: == set exact

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson