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”的文件来说非常合适,该文件已经存在于缓存中
并返回文件. 现在我希望这样
所以我试着这样做: case Some(_) => { println(s"File " $file " found!"); file.get} 编译器抛出
为什么这样,如何正确地转义双引号,并且最好在$file-variable之后或之前没有空格? 解决方法
使用三引号:
scala> s"""File "$file" found!""" res0: String = File "blubb" found! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |