Description:
Dynamically parse and compute the expression.
Syntax:
eval(StringExp ,{argExp},…)
Note:
The function dynamically parses string StringExp and returns result.
In StringExp, ? represents a parameter and argExp represents a parameter value. There is a one to one correspondence between ? and argExp according to position when numbers of the two are same.
When the number of ? is more than that of argExp, the extra ? will get assigned starting again from the first argExp.
You can also use ?i method to specify a value for a ? through serial number i, as in eval( "?2/?1", 3, 6 ), where the first ? corresponds to the second parameter value, and the second ? corresponds to the first, that is, the parsing expression is 6/3 and 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. |