在 Eclipse 中粘贴多行 Java 字符串
不幸的是,Java 没有多行字符串文字的语法。如果 IDE 可以轻松处理诸如
String x = "CREATE TABLE TEST ( \n"
+ "A INTEGER NOT NULL PRIMARY KEY, \n"
...
使用 Eclipse 将多行字符串从剪贴板粘贴到 Java 源的最快方法是什么(以自动创建上述代码的方式)之类的构造,那就没问题了。
Unfortunately, Java has no syntax for multi-line string literals. No problem if the IDE makes it easy to work with constructs like
String x = "CREATE TABLE TEST ( \n"
+ "A INTEGER NOT NULL PRIMARY KEY, \n"
...
What is the fastest way to paste a multi-line String from the clipboard into Java source using Eclipse (in a way that it automatically creates code like the above).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
好吧,我刚刚找到了答案(在 Stackoverflow 上,同样如此)。
Eclipse 有一个选项,将多行文本复制粘贴到字符串文字中将导致带引号的换行符:
Okay, I just found the answer (on Stackoverflow, no less).
Eclipse has an option so that copy-paste of multi-line text into String literals will result in quoted newlines:
您可以使用此 Eclipse 插件:http://marketplace.eclipse.org/node/491839#.UIlr8ZDwCUm
这是一个多行字符串编辑器弹出窗口。将插入符号放入字符串文字中,按 ctrl-shift-alt-m 并粘贴文本。
You can use this Eclipse Plugin: http://marketplace.eclipse.org/node/491839#.UIlr8ZDwCUm
This is a multi-line string editor popup. Place your caret in a string literal press ctrl-shift-alt-m and paste your text.
如果您在 TOAD 或其他面向 SQL 的 IDE 等工具中构建 SQL,它们通常会将标记复制到剪贴板。例如,TOAD 有一个 CTRL+M,它可以在编辑器中获取 SQL,并完全执行上面代码中的操作。它还涵盖了相反的情况……当您从 Java 中获取格式化字符串并希望在 TOAD 中执行它时。将 SQL 粘贴回 TOAD 并执行 CTRL+P 以删除多行引号。
If your building that SQL in a tool like TOAD or other SQL oriented IDE they often have copy markup to the clipboard. For example, TOAD has a CTRL+M which takes the SQL in your editor and does exactly what you have in your code above. It also covers the reverse... when your grabbing a formatted string out of your Java and want to execute it in TOAD. Pasting the SQL back into TOAD and perform a CTRL+P to remove the multi-line quotes.
请参阅: Multiple-line-syntax
它还支持以下变量多行字符串,例如:
输出:
See: Multiple-line-syntax
It also support variables in multiline string, for example:
Output:
EclipsePasteAsJavaString 插件允许您通过 Ctrl + Shift + V
示例
粘贴 将文本作为 Java 字符串插入像往常一样通过 Ctrl+V:
一些带有制表符的文本
和新的
lines
通过 Ctrl+Shift+V 粘贴为 Java 字符串
"some text\twith tabs\r\n" +
“和新的\r\n”+
“线”
The EclipsePasteAsJavaString plug-in allows you to insert text as a Java string by Ctrl + Shift + V
Example
Paste as usual via Ctrl+V:
some text with tabs
and new
lines
Paste as Java string via Ctrl+Shift+V
"some text\twith tabs\r\n" +
"and new \r\n" +
"lines"
据我所知,这似乎超出了 IDE 的范围。
Copyin ,您可以复制字符串,然后尝试使用 ctrl+shift+F 对其进行格式化
大多数情况下,这些多行字符串不使用硬编码,而是应从属性或 xml 文件中使用。可以在稍后的时间点进行编辑,无需更改代码
As far as i know this seems out of scope of an IDE.
Copyin ,you can copy the string and then try to format it using ctrl+shift+ F
Most often these multiline strings are not used hard coded,rather they shall be used from property or xml files.which can be edited at later point of time without the need for code change