Quick actions

cmd+k|ctrl+k

Navigation

Languages

Scope Function with Lambda Receiver (With)

Snippet info

Language

Kotlin

Visibility

public

Author

habib17

Created

2019-11-02T01:03:54Z

Updated

2019-11-02T01:03:54Z

fun main(args : Array<String>){
//withTwo()
withOne()
}

fun withOne(){
    val message = "Hello Kotlin!"
    val result = with(message){
        println("value is $this")
        println("with length ${this.length}")
    }
}

fun withTwo(){
    val message = "Hello Kotlin!"
    val result = with(message){
        "First character is ${this[0]}" +
        " and last character is ${this[this.length - 1]}"
    }
    println(result)
}
INFO