Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Shortcut to Split Long Strings

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";
like image 587
Paul Croarkin Avatar asked Nov 02 '08 19:11

Paul Croarkin


People also ask

How to split string in Eclipse?

We can use \\s+ (which means one or more whitespace characters in regex) to split a string by spaces.

How do I skip to the end of a line in Eclipse?

End key to move on end of the line, Home key to move on beggining of line. Same for NetBeans and IntellijIDEA.

How do I select all text in Eclipse?

Show activity on this post. Press ctrl + f for windows computer.


2 Answers

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 :)

like image 175
Jon Skeet Avatar answered Nov 16 '22 07:11

Jon Skeet


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.

like image 29
Fylke Avatar answered Nov 16 '22 08:11

Fylke