用Kotlin字符串转义$ {something} [英] Escape ${something} in a Kotlin String
本文介绍了用Kotlin字符串转义$ {something}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
定义包含声明模板替换字符的Kotlin字符串的正确方法是什么,但不是将其评估为模板?
What is the correct way of defining a Kotlin string that includes the characters for declaring a template substitution, but not have this evaluated as a template?
例如:"${something}"
只是被视为普通字符串.
For example: "${something}"
just treated as an ordinary string.
我想使用Spring值注释:
I would like to use the Spring value annotation:
@Value("${some.property}) lateinit var foobar : String?
推荐答案
这对我有用:
val s = "\${foo}"
println("s = ${s}") // prints s = ${foo}
记录的方式也可以正常工作:
val s = "${'$'}{foo}"
println("s = ${s}") // prints s = ${foo}
这篇关于用Kotlin字符串转义$ {something}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文