Skip to content Skip to sidebar Skip to footer

I Have String With Numbers When Getting The Char From String It Shows '0'48 In Kotlin. How To Get The Char Alone In Kotlin

Here we initialize a variable and get the first element but the expected result is not obtained var temBits = '00000000000000000001' temBits.elementAt(0)` Result = '0' 48 expected

Solution 1:

The result is displayed as 48 as 48 is the ascii value of 0. Converting to integer would help.

Try:

temBits.elementAt(0).toString().toInt()

Solution 2:

48 is the ASCII (and others which are compatible to ASCII in the lower ranges) encoding of the character '0'. It's your tool through which you obtain the result which formats the result (which is what you actually expect) to give you more information.

Post a Comment for "I Have String With Numbers When Getting The Char From String It Shows '0'48 In Kotlin. How To Get The Char Alone In Kotlin"