Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate string expression in kotlin without using script engine

I want to evaluate the string expression without using script engine:

string expression can be like:

"((true&&(!false)||true)&&true)&&true"

Anybody have any idea how this can be done in android using kotlin

Thanks

like image 506
Pragya Singla Avatar asked Mar 15 '26 03:03

Pragya Singla


1 Answers

Kotlin Android


app.gradle file

Add a new dependency

dependencies {
    implementation 'net.objecthunter:exp4j:0.4.8'
}

main.kt file

    var value = TextView.text.toString()
    var result = ExpressionBuilder(value).build().evaluate()
like image 54
Rahul Avatar answered Mar 17 '26 15:03

Rahul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!