views:

1392

answers:

4

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 automagically creates code like the above).

A: 

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

Ravisha
Disagree. This is totally in scope of an IDE. After all, you can edit a String, and type enter in the middle of it and Eclipse creates a proper Java multi-line string.
Thilo
@Thilour question was to copy a string into an editor which was not in a format as per the IDE ,but still u want it to automatically make these arrangements for you!Which i belive is out of perview of the IDE.Tell me one thing what exactly is ur requirement.Why u want to copy string?so that we get clarity of problem.Pls edit question rather comment
Ravisha
A: 

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.

Brian
+11  A: 

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:

Preferences/Java/Editor/Typing/ "Escape text when pasting into a string literal"

Thilo
It should be noted that after enabling the feature you still have to first write two quotation marks and then paste the text inside those marks.
Lycha
A: 

There is a great website that do this work for you, i have discovered it 1min ago! =)

http://sqlinform.com/online.phtml

Andre Costa