Java实现计算字符串表达式

一个java 的计算字符串表达式的组件

官方站点:http://www.japisoft.com/formula/

 

贴一下支持的操作符:

FormulaOperators :

Type
Operator
Example
Numerical operators
+ - * / : Basic operators
% : Modulo operators (not in high precision )
^ : Power operators (not in high precision )
(-1 + 50*2 ) / ( 2^4 )
Boolean operators
~, xor : operators
&&, and : And operators
||, or : Or operators
!, not : Not operators
< : less operator
> : great operator
<= : less or equal operator
>= : great or equal operator
==, equals : equal operators
!=, <> : not equal operators


!(A && (B < 10))  |  NOT ( A XOR ( B equals C ) )
A != 2 || B > 2
"string1" == "string2"
A or B
A or ( B <> C )
String operators
== : 2 strings equals
!= : 2 strings not equals
<> : 2 strings not equals
< : The first string less lexically than
the second one
> : The first string great lexically than
the second one
<= :The first string less or equals lexically than
the second one
>= : The first string great or equals lexically than
the second one
+ : Concat string
"string1" == "string2"  : false
"string1" + "a" : "string1a"
"abc" > "aaa" : true
"zyx" < "bcd" : false



List operators
+ : Concat two lists
- : Substract a list to another one
in : Test if an element is inside a list
(1,2)+(3,4) = (1,2,3,4)
(1,2) + 3 = (1,2,3)
3+(1,2)=(1,2,3)
(1,2,3,4)-(3,4)=(1,2)
(1,2,3,4)-3=(1,2,4)
2 in (1,2,3)=true
4 in (1,2,3)=false
Other operators
= : set a variable operator
[] : absolute value
² : power 2 operator
% : Percent operators
A = [ 2 - A ] * 2

10%=0.1
Conditional operators
if then
if then else
if ( A > 2 ) then "Ok"
if ( A <=2 ) THEN B=3 else B=4

你可能感兴趣的:(java,C++,c,C#)