加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 字符串插值,转义引号

发布时间:2020-12-16 09:03:38 所属栏目:安全 来源:网络整理
导读:这有点困难,我有点困惑.我已经查看了stackoverflow,但没有解决方案似乎对我来说很好. 我想做的事: val file = checkcache(fileName)file match{ case Some(_) = {println(s"File $file found!"); file.get} case None = createFile(fileName)} 现在,这对于
这有点困难,我有点困惑.我已经查看了stackoverflow,但没有解决方案似乎对我来说很好.

我想做的事:

val file = checkcache(fileName)

file match
{
    case Some(_) => {println(s"File $file found!"); file.get}
    case None => createFile(fileName)
}

现在,这对于名为“blubb”的文件来说非常合适,该文件已经存在于缓存中

File blubb found

并返回文件.

现在我希望这样

File “blubb” found

所以我试着这样做:

case Some(_) => { println(s"File " $file " found!"); file.get}

编译器抛出

‘)’ expected but string literal found.

为什么这样,如何正确地转义双引号,并且最好在$file-variable之后或之前没有空格?

解决方法

使用三引号:

scala> s"""File "$file" found!"""
res0: String = File "blubb" found!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读