zoukankan      html  css  js  c++  java
  • Scala字符串插值

    Scala提供了三种字符串插值方式:s,f和raw。
    1. s字符串插值器
    简单的说就是解析字符串变量。

        val name = "Tom"
        println(s"His name is $name")
        println(s"His name is ${name}my")
        println(s"23 + 78 = ${23+78}")

    第2行是最简单的用法,第3行为了区分变量名加了{},第4行是进行了运算。

    运行结果:

    2. f字符串插值器

    可以进行格式化的输出,变量名后用%指定格式,如果没有指定,其作用和s是一样的。

        val hei = 2.345
        println(f"The height is $hei%2.2f")
        println(f"The height is $hei%2.5f")

    运行结果:

    3. raw插值器

    让字符串原封原样的输出,屏蔽控制效果。

    println(raw"/t/n")

    运行结果:

  • 相关阅读:
    phpcs
    asp.net之cookie
    ajax技术
    union、except和intersect查询
    外连接查询
    对查询结果分组
    聚合函数查询
    数据库的约束
    数据库备份
    fusionCharts
  • 原文地址:https://www.cnblogs.com/mstk/p/6901119.html
Copyright © 2011-2022 走看看