2

How to align group of lines into String automatically in Eclipse?

For Example

String s = "{ "QUOTE_DETAILS": { 
                             "BRANCH_CODE": "0000",
                             "TRANSACTION_TYPE": "TTTT",
                             "EXPIRY_DATE": "10/11/2012"
                            }}

Above group of lines should be auto aligned as

String s = "{ \"QUOTE_DETAILS\": { "
                          +"\"BRANCH_CODE\": "0000\", \"TRANSACTION_TYPE\": \"TTTT\","
                          +"\"EXPIRY_DATE": \"10/11/2012\""
                          +"  }}";

Do we have any option to achieve this?

Above example is just a sample, In reality I has some 40 odd lines of data, which need to be converted into String in java.

Ravi G
  • 859
  • 1
  • 8
  • 21

1 Answers1

6

Go to Preferences --> Java --> Editor --> Typing --> In String literals, and check if option Escape text when pasting into a string literal is enabled.

rlegendi
  • 10,466
  • 3
  • 38
  • 50
  • Thanks for your response.. but i don't see any change after checking that check box. – Ravi G Nov 14 '12 at 04:53
  • i) Are you using the Java editor? ii) Have you applied the changes? iii) Try using it by writing `String s = ""`, then pasting the data *between* the quotation marks, iv) Press *Ctrl+Shift+F* for autoformatting. I believe it should work. – rlegendi Nov 14 '12 at 08:43