Conversion of values of type Strings

Hello, I’m having trouble converting values ​​of type String to Int

example, I want to convert this String to int
would be :
var vlConvResult: String = “10 + 1-2”
lxl: Integer = Integer (vlConvResult)
System.out.println (lxl) // result 9

I did like this

   var lvx = tfcont.getText ()
        var lxl: Integer = Integer (lvx)
        System.out.println (lvx.toString ())


I suspect you misunderstand the API.
Are you looking for an expression evaluator?

1 Like

tell me what do you think i didn’t understand? I am a student, I need to solve this doubt … I have been practicing kotlin lately … if you know what I read a lot javafx in version 1.0 to 1.2,
only in this way did I understand how java works with kotlin.
I found some ways to resolve this issue using both java and kotlin

however … should i use java to do this conversion and print values ​​or should i use kotlin to print the values ​​to me? lol I hope you understood me … lol
see you later :slight_smile:

I think there’s a misunderstanding here.

What @fvasco want to say is that in stdlib, (both in kt and java), you will find tools to convert a string representing a single integer value.

Example :

  • "10".toInt() == 10
  • "20_123".toInt() == 20123

But what you describe is an operation between two integers

For that, you’ll likely have to integrate a third-party tool, or code it yourself if accepted patterns are not complex (using regex for example).

But I think that there’s another question implicit, about java / kt interop. Maybe try to add details to your question (what error has been raised, what you cannot find/understand from documentation, etc), to help people giving precise solutions.