gpt4 book ai didi

java - 在 Eclipse 的复制/粘贴中保留格式

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

有一些生成的代码可以构建 map 。放置在 map 中的值是多行字符串。
示例:

theMap.put("SOMEKEY", "Line 1 of string.  
Also line 2 of string.
Perhaps more");

当我尝试将代码复制/粘贴到 Eclipse 时,由于 map 中值的格式,我收到红色错误。
我用谷歌搜索并found这里 Eclipse 中有一个配置可以保留字符串文字中的格式,但在这种情况下它似乎不起作用。
还有其他配置选项吗?

最佳答案

如果您只需要保留空格,请使用\n 字符,如下所示:

theMap.put("SOMEKEY", "Line 1 of string.\nAlso line 2 of string.\nPerhaps more"); 

或者如果你想要多行:

theMap.put("SOMEKEY", "Line 1 of string."
+"\nAlso line 2 of string."
+"\nPerhaps more");

如果仅将字符串值粘贴到空字符串 ("") 中,则需要启用以下设置才能执行此操作:window>preferences>java>editor>typing and检查最后一个选项(粘贴到字符串文字时转义文本)

关于java - 在 Eclipse 的复制/粘贴中保留格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14236481/

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