在Scala中同时支持引用和字符串替换
我有以下几行回复在Scala中同时支持引用和字符串替换,scala,Scala,我有以下几行回复 scala> val accountID = "123" accountID: String = 123 scala> s"{\"AccountID\":\$accountID\, \"ProcessMessage\":\"true\", \"Reason\":\"Integration Test Message\"}" <console>:1: error: ';' expected but string literal found. s"{\"
scala> val accountID = "123"
accountID: String = 123
scala> s"{\"AccountID\":\$accountID\, \"ProcessMessage\":\"true\", \"Reason\":\"Integration Test Message\"}"
<console>:1: error: ';' expected but string literal found.
s"{\"AccountID\":\"$accountID\", \"ProcessMessage\":\"true\", \"Reason\":\"Integration Test Message\"}"
^
scala>val accountID=“123”
accountID:String=123
scala>s“{\“AccountID\”:\$AccountID\,\“ProcessMessage\”:\“true\,\“Reason\”:\“Integration Test Message\”}”
:1:错误:';'应为字符串文字,但找到字符串文字。
s“{\“AccountID\”:\“$AccountID\”,\“ProcessMessage\”:\“true\”,“Reason\”:“Integration Test Message\”}
^
我想这是一件很小的傻事,但我还是想知道我做错了什么。如果我直接输入帐户ID,它的评估结果很好 使用三重引号并删除
\
s
scala> s"""{"AccountID":"${accountID}", "ProcessMessage":"true", "Reason":"Integration Test Message"}"""
res6: String = {"AccountID":"123", "ProcessMessage":"true", "Reason":"Integration Test Message"}
使用三重引号并删除
\
s
scala> s"""{"AccountID":"${accountID}", "ProcessMessage":"true", "Reason":"Integration Test Message"}"""
res6: String = {"AccountID":"123", "ProcessMessage":"true", "Reason":"Integration Test Message"}
在搜索长字符串中的错误之前,这里会产生基本相同的错误:
s“\”
。显然,s
不喜欢\”
,无论出于何种原因。只需使用pamu的解决方案。在搜索长字符串中的错误之前,这里会产生基本相同的错误:s“\”
。显然,s
不喜欢\”
,无论出于什么原因。只需使用pamu的解决方案。