Home > database >  How to remove first char in kotlin string
How to remove first char in kotlin string

Time:01-23

What's up! So I'm trying to make a calculator in Android Studio with kotlin and i try to allow users to make numbers negative and positive, but I got only half of it, making number negative, but can't make it so it turn back to positive, for it I need to remove first char in string, someone knows how to do it? Thanks in advance!

    var firstNumber: String = ...
    if (firstNumber[0] == '-') {
       firstNumber.
    }

CodePudding user response:

You can use drop() of String class to remove first char of string.

firstName = firstName.drop(1);

CodePudding user response:

You could use substring:

firstNumber = firstNumber.substring(1);
  •  Tags:  
  • Related