字符串中的美元符号字符 [英] Dollar Sign Character in Strings

查看:53
本文介绍了字符串中的美元符号字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在字符串文字中添加 $ 字符最干净的方法是什么?

What is the cleanest method for adding a $ character in a string literal?

到目前为止,我想出的最好的解决方案是""$ {" $} ..."",对我来说看起来很丑.

The best solution I've come up with so far is """${"$"}...""", which looks ugly to me.

推荐答案

要在字符串文字中转义美元符号,请使用反斜杠字符:

To escape the dollar sign inside a string literal, use the backslash character:

"\$"

要以 raw 字符串文字("" ..."")进行转义,您提供的解决方法确实是目前最简单的解决方案.错误跟踪器中存在一个问题,您可以对其加注星标和/或投票: KT-2425 .

To escape it in a raw string literal ("""..."""), the workaround you provided is indeed the easiest solution at the moment. There's an issue in the bug tracker, which you can star and/or vote for: KT-2425.

这篇关于字符串中的美元符号字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆