Kotlin - String template

Using String Templates

Use kotlin $instead of java +to concatenate strings.

    val garden="公园"
    val time=3
    println("我去${
      
      garden}玩了${
      
      time}小时")
//输出:我去公园玩了3小时

Insert expressions inside string templates:

    val isLogin=false
    println("server response result:${
      
      if (isLogin) "登录成功" else "登录失败"}")
//输出:server response result:登录失败

Guess you like

Origin blog.csdn.net/qq_43867812/article/details/131368954