Difference between revisions of "Recital Operators"
Yvonnemilne (Talk | contribs) (→String Substitution Operator) |
Yvonnemilne (Talk | contribs) (→Comparison Operators) |
||
Line 84: | Line 84: | ||
The Comparison Operators are always evaluated from left to right. | The Comparison Operators are always evaluated from left to right. | ||
+ | |||
+ | The following ’wildcard’ characters can be used for == pattern matching: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | !Character||Action | ||
+ | |- | ||
+ | |?||Matches any one character | ||
+ | |- | ||
+ | |%||Matches any one character | ||
+ | |- | ||
+ | |*||Matches zero or more characters | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | In SQL statements, the following wildcard characters are available: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | !Characters||Description | ||
+ | |- | ||
+ | |_||Matches any one character | ||
+ | |- | ||
+ | |%||Matches zero or more characters | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | Note: For FoxPro compatibility reasons, wildcard pattern matching is not available when [[SET COMPATIBLE]] is set to FOXPRO/FOXBASE/FOXPLUS/VFP. | ||
+ | |||
+ | '''Example''' | ||
+ | <code lang="recital"> | ||
+ | cSTR1 = [Welcome to Recital] | ||
+ | ? "Recital" $ cSTR1 | ||
+ | .T. | ||
+ | |||
+ | cSTR2 = [Welcome] | ||
+ | // Compares to the end of cSTR2 | ||
+ | ? cSTR1 = cSTR2 | ||
+ | .T. | ||
+ | |||
+ | // Compare contents & size | ||
+ | ? cSTR1 == cSTR2 | ||
+ | .F. | ||
+ | </code> | ||
===Increment and Decrement Operators=== | ===Increment and Decrement Operators=== |
Revision as of 14:11, 6 November 2009
Contents
Recital Operators
Assignment Operators
Values are assigned to memory variables using the the equals = operator or the inline assignment := operator.
cVAR1 = 'newer value' cVAR1 := 'newest value'
Note that the store command can also be used to assign valuesand can operate on more than one memory variable in a single command.
store 'new value' to cVAR1, cVAR2
Arithmetic Operators
Recital supports the use of the following Arithmetic Operators:
Operator | Operation | Precedence |
---|---|---|
() | Parentheses | 1 |
** | Exponentiation | 2 |
* | Multiplication | 3 |
/ | Division | 3 |
% | Modulus/Remainder | 3 |
+ | Addition | 4 |
- | Subtraction | 4 |
When dealing with Date data types, the operators work as follows:
Operator | Operation |
---|---|
+ | <expD> + <expN> returns a date plus the number of days specified in <expN>. |
- | Returns the interval between the two dates as a number of days. |
Example
? 2*3^2 18 ? 2*25%7 1.00 ? date() + 30 - date() 30
Comparison Operators
The following Comparison Operators are supported in Recital:
Operator | Operation |
---|---|
= | Equal To |
== | Exactly Equal To / Matches Pattern |
<> | Not Equal To |
!= | Not Equal To |
# | Not Equal To |
> | Greater Than |
>= | Greater Than or Equal To |
< | Less Than |
<= | Less Than or Equal To |
The Comparison Operators are always evaluated from left to right.
The following ’wildcard’ characters can be used for == pattern matching:
Character | Action |
---|---|
? | Matches any one character |
% | Matches any one character |
* | Matches zero or more characters |
In SQL statements, the following wildcard characters are available:
Characters | Description |
---|---|
_ | Matches any one character |
% | Matches zero or more characters |
Note: For FoxPro compatibility reasons, wildcard pattern matching is not available when SET COMPATIBLE is set to FOXPRO/FOXBASE/FOXPLUS/VFP.
Example
cSTR1 = [Welcome to Recital] ? "Recital" $ cSTR1 .T. cSTR2 = [Welcome] // Compares to the end of cSTR2 ? cSTR1 = cSTR2 .T. // Compare contents & size ? cSTR1 == cSTR2 .F.
Increment and Decrement Operators
The ++ operator is used to automatically increment a previously declared numeric memory variable by one. The ++ operator must be placed at the beginning of the command line.
Example
i=0 do while i <100 ++ i enddo
The -- operator is used to automatically decrement a previously declared numeric memory variable by one. The -- operator must be placed at the beginning of the command line.
Example
i=100 do while i > 0 --i enddo
String Concatenation Operator
When dealing with string data types, the + and - operators perform the following concatenation operations:
Operator | Operation |
---|---|
+ | Concatenate the right hand string to the end of the left hand string. |
- | Concatenate the right hand string to the end of the left hand string after trimming the left hand string of trailing spaces. |
Example
? [Hello] + [ ] + [ World] Hello World ? [Hello ] - [ World] Hello World
String Search Operators
The following String Search Operators are supported in Recital:
Operator | Operation |
---|---|
$ | Substring is Contained In |
| | Contains Substring |
String Substitution Operator
&<memvar> | (<exp>)
The & String Substitution or Macro Operator substitutes the contents of the specified <memvar> or evaluated expression, (<exp>), into the command line. To use a macro in the middle of a word, it is necessary to end the variable name with a '.'. Any type of memory variable can be substituted as a macro; expressions must be enclosed in round brackets.
Example
subscript = 10 i10i = 5 ? i&subscript.i 5
Execution Operator
The ! Execution Operator provides the facility for running operating system commands or external programs from within the system. The !! operator works in the same way, but any output is displayed at the current screen location rather than the top of the screen.
Example
! ps -ef !! ps -ef
Concatenation of Strings and Other Data Types
If SET STRICT is OFF, non-string expressions are automatically converted as they are added to a string. If SET STRICT is ON, expressions must be converted manually using the ETOS() or other data conversion functions. By default, STRICT is ON.
Example
set strict off echo "This string can add numerics and dates etc. " + 100.89 + " " + date() set strict on echo "This string can add numerics and dates etc. " + str(100.89,6,2) + " " + etos(date())