Eclipse 分割长字符串的快捷方式

发布于 2024-07-07 22:28:00 字数 266 浏览 4 评论 0原文

我发誓我见过有人这样做,但我在各种快捷方式列表中找不到它。

鉴于:

String s = "A very long ............................ String";

是否有 Eclipse 快捷方式将其变成:

String s = "A very long ............................ " 
    + "String";

I swear I've seen someone do this, but I can't find it in the various lists of shortcuts.

Given:

String s = "A very long ............................ String";

Is there an Eclipse shortcut to turn it into:

String s = "A very long ............................ " 
    + "String";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

暮凉 2024-07-14 22:28:00

是的 - 当光标位于字符串中间时,只需按回车键即可。

不可否认,这将 + 放在第一行的末尾而不是第二行的开头,如果您的风格指南要求后者,这会很烦人,但如果您不挑剔,那就太好了:)

Yup - just hit return when your cursor is in the middle of the string.

Admittedly that puts the + at the end of the first line instead of the start of the second, which is irritating if your style guide demands the latter, but if you're not fussy it's great :)

海的爱人是光 2024-07-14 22:28:00

Eclipse 中的所有格式化模板都会将加号放在下一行(我觉得这真的很烦人),因此您只需应用代码格式化程序,加号就会出现在下一行。

All the formatting templates in Eclipse will put the plus on the next row (which I find really annoying), so you can simply apply the code formatter and the plus will end up on the next row.

请叫√我孤独 2024-07-14 22:28:00

对于此问题也可能有一个快速修复(Ctrl + 1)。

在 3.4 中,我惊讶地发现有一些快速修复可以将基于 + 的字符串连接转换为 StringBuilderMessageFormat 的使用。 杰出的!

There may be a Quick Fix (Ctrl + 1) for this as well.

I was amazed in 3.4 to discover that there are Quick Fixes to transform +-based string concats into uses of StringBuilder or MessageFormat. Brilliant!

风透绣罗衣 2024-07-14 22:28:00

您还可以使用正则表达式格式化代码。 选择表达式,按 Ctrl+F 并使用:

查找:"\s*?\+\s*?\R(\s*?)"

替换为:"\R$1\ + "

☑ 正则表达式

Also you can format code using regular expression. Select expression, press Ctrl+F and use:

Find: "\s*?\+\s*?\R(\s*?)"

Replace with: "\R$1\+ "

☑ Regular expressions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文