File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Formatting problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Formatting problem" Watch "Formatting problem" New topic

Formatting problem

Jim Frank

Joined: Mar 13, 2004
Posts: 27
I am working on an application which allows the user to save a log entry. The users want to cut and paste from MS Word into a JTextField. The problem is is when this is saved, to a String, blocks and weirds characters are saved too, which I think are the tab and other special characters from Word that are not converting right. How can I strip out these characters? I think it is mostly the enter and tab characters that are causing the problems.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this would need a fair bit of testing

String textToSave = textField.getText().replaceAll("[\\t\\n\\x0B\\f\\r]","");

basically the 'whitespace' characters, except for 'space' itself
Jim Frank

Joined: Mar 13, 2004
Posts: 27
I agree. Here's the link:
subject: Formatting problem
It's not a secret anymore!