Export (0) Print
Expand All

String and Value Comparison in Visual FoxPro

Visual Studio 2005

Visual FoxPro has two relational operators that test for equality: the equal sign (=) operator and the double equal sign (==) operator. You can use the = operator to perform a comparison between two values of the same type and is suitable for comparing data of Character, Numeric, Date, and Logical type. However, when you compare character expressions with the = operator, the results might not exactly as expected.

Character expressions are compared character for character from left to right until one of the expressions does not equal the other or until the end of the expression on the right of the = operator is reached, as specified by setting the SET EXACT command to OFF, or until the ends of both expressions are reached, as specified by setting the SET EXACT command to ON.

You can use the == operator to perform an exact comparison of character or binary data. If you compare two character or binary expressions using the == operator, the expressions on both sides of the == operator must contain precisely the same characters or bytes, including spaces or zero (0) bytes, respectively, to be considered equal. The SET EXACT setting is ignored when character strings or binary expressions are compared using the == operator. For more information, see Relational Operators.

The following table shows how the choice of operator and the SET EXACT setting affect comparisons.

NoteNote

An underscore represents a blank space.

Comparison = with SET EXACT OFF = with SET EXACT ON == with SET EXACT ON or OFF

"abc" = "abc"

Match

Match

Match

"ab" = "abc"

No match

No match

No match

"abc" = "ab"

Match

No match

No match

"abc" = "ab_"

No match

No match

No match

"ab" = "ab_"

No match

Match

No match

"ab_" = "ab"

Match

Match

No match

"" = "ab"

No match

No match

No match

"ab" = ""

Match

No match

No match

"__" = ""

Match

Match

No match

"" = "___"

No match

Match

No match

TRIM("___") = ""

Match

Match

Match

"" = TRIM("___")

Match

Match

Match

When working with SQL statements such as SELECT - SQL Command, the SET ANSI setting can affect results if you use the = operator.

Community Additions

ADD
Show:
© 2014 Microsoft