When you paste some text in to a string have you seen this?

The problem is that the string is not escaped. This gives you a error. Fixing this is not easy if you have pasted text that needs a lot of escaping. I have encountered this a few times. It is annoying.

Luckily Eclipse has a simple solution for this. Go to Window>Preference>Java>Editor>Typing and check the “Escape text when pasting into a string literal“. Now when you paste the same text here is what you get:

Nice. What would make this feature more discoverable would be when pasting the string an icon should pop up like in Microsoft Word and provide you an option to paste the escaped string…

Related posts:
- Eclipse Tip: Auto-generate compilation units by pasting snippets
- Eclipse Tip: Navigating stack traces
- Eclipse Tip: Format edited lines on Save
- Eclipse Tip: Block Selection Mode
- AutoHotKey: Paste Plain Text
Peter Štibraný
March 10, 2009 at 1:49 PM
Very useful. Thanks for sharing!
Vasanth Dharmaraj
March 10, 2009 at 2:03 PM
@ Peter Štibraný
You are welcome.
Madhu
March 10, 2009 at 10:27 PM
Hello Vasanth,
Thanks for the tip. Its very useful.
Vasanth Dharmaraj
March 11, 2009 at 5:32 AM
You are welcome