Description:
Dynamically parse and compute the expression.
Syntax:
eval(StringExp ,{argExp})
Note:
The function parses the expression string StringExp, evaluate it, and return its result. In the expression string, the value of a keyword ? corresponds to the result of evaluating the expression argExp. If there are more than one ?, then there may be more than one argExp.
Generally there is a one-to-one correspondence between argExp and ?.
If the number of ? is more than that of argExp, then the extra ? will get assigned starting from the first argExp again.
You can use a number to specify the corresponding parameter for a ?, as in eval( “?2/?1”, 3, 6 ), where the first ? corresponds to the second parameter, and the second ? corresponds to the first parameter, the result is 2. ?0 represents a sequence of all parameters.
Parameter:
StringExp |
An expression string to be calculated |
argExp |
Parameter expression |
Option:
@s |
Only return the parsed expression without computing it. |
Function keyword:
? |
Used in StringExp to represent the value of argExp |
Return value:
Result of the specified expression whose data type is determined by the expression itself.
Example:
|
A |
|
1 |
=”1+3” |
|
2 |
=eval(A1) |
4. |
3 |
=4 |
|
4 |
=eval("?+5",A3) |
? is a key word, its value is A3, and the function returns the result of 9. |
5 |
=eval("(?+1)/?",3,4) |
The first ? is 3, the second ? is 4, and the returned result is 1.0. |
6 |
=eval("(?+?)*?",1,3) |
The first ? is 1, the second ? is 3, the third ? is 1 again, the returned result is 4. |
7 |
=eval("?+?",3) |
The result is 6 because the number of argExp is less than ?, so argExp will be used repeatedly. |
8 |
=eval("?2/?1",3,6) |
The first ? corresponds to the second parameter, the second ? corresponds to the first parameter, so the result is 2.0. |
9 |
=eval( "?0.len()", 3,6) |
Return the length of ?0, which is the sequence made up of all parameters. |
10 |
=eval@s( "(?+?)*?",1, 3 ) |
Use @s option to return the parsed expression only, without computing it; the result returned is (1+3)*1. |