Eclipse 分割长字符串的快捷方式
我发誓我见过有人这样做,但我在各种快捷方式列表中找不到它。
鉴于:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的 - 当光标位于字符串中间时,只需按回车键即可。
不可否认,这将 + 放在第一行的末尾而不是第二行的开头,如果您的风格指南要求后者,这会很烦人,但如果您不挑剔,那就太好了:)
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 :)
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.
对于此问题也可能有一个快速修复(Ctrl + 1)。
在 3.4 中,我惊讶地发现有一些快速修复可以将基于 + 的字符串连接转换为
StringBuilder
或MessageFormat
的使用。 杰出的!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
orMessageFormat
. Brilliant!您还可以使用正则表达式格式化代码。 选择表达式,按 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