get

operator fun Int.get(digit: Int): Int

Retrieves the digit at a specific position (from right to left, 0-indexed) in an integer.

This operator allows accessing individual digits of an integer using the index operator []. The index digit represents the position of the desired digit, starting from 0 for the rightmost digit (the ones place).

Example:

val number = 12345
val onesPlace = number[0] // Result: 5
val tensPlace = number[1] // Result: 4
val hundredsPlace = number[2] // Result: 3
val thousandsPlace = number[3] // Result: 2
val tenThousandsPlace = number[4] // Result: 1
val nonExistentPlace = number[5] // Result: 0

Return

The digit at the specified position. Returns 0 if the index is out of bounds (greater than the number of digits).

Parameters

digit

The 0-based index of the digit to retrieve, where 0 is the rightmost digit.


operator fun String.get(range: IntRange): String

Allows slicing a string using an IntRange with an inclusive end.

This operator provides a convenient way to get a substring using range notation (e.g., myString[0..4]). It behaves similarly to Python's string slicing.

Return

A new string containing the characters from the starting index to the ending index of the range, inclusive.

Parameters

range

The inclusive range of indices to extract.

Throws

if the range is outside the bounds of the string.

Example:

val text = "Hello, World!"
val slice = text[0..4] // equivalent to text.substring(0, 5)
println(slice) // Outputs: "Hello"