在Dart中如何在原始字符串中进行字符串插值。

huangapple go评论54阅读模式
英文:

How to do string interpolation in raw strings in dart

问题

我可以在普通字符串中使用 $ 符号进行字符串插值,

但是如何在原始字符串中执行插值呢。

r"这是原始字符串"

因为在原始字符串中像这样使用 $ 符号进行插值是无效的。

r"我的名字是 $name"

英文:

I can do the string interpolation using $ sign in normal strings

but how can I perform interpolation in raw strings.

r"this is a raw string"

because $ sign for interpolation is not working in raw strings like this

r"my name is $name"

答案1

得分: 3

根据语言规范,我认为从原始字符串内部不起作用。但是你可以这样做:

r"my name is ""$name""r". Blah blah."
英文:

I think, according to language specification it wouldn't work from within the raw string. However you could do this:

r"my name is ""$name"r". Blah blah.";

huangapple
  • 本文由 发表于 2023年7月3日 21:47:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76605362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定