gpt4 book ai didi

scala - 在 f 字符串插值中转义引号

转载 作者:行者123 更新时间:2023-12-02 06:03:01 25 4
gpt4 key购买 nike

我无法在以下字符串插值器中包含引号:

f"foo ${math.abs(-0.9876f)*100}%1.1f%%"

输出是
foo 98.8%

现在所需的输出是
foo "98.8%"

插入 \"不起作用,只会产生“未关闭的字符串文字”错误。

最佳答案

好像是this problem wouldn't be fixed .您可以使用以下解决方法之一:

  • 多行字符串:
    f"""foo "${math.abs(-0.9876f)*100}%1.1f%""""
  • \042 :
    f"foo \042${math.abs(-0.9876f)*100}%1.1f%\042"
  • ${'"'} :
    f"foo ${'"'}${math.abs(-0.9876f)*100}%1.1f%${'"'}"
  • 关于scala - 在 f 字符串插值中转义引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17085354/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com