Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting problem

 
Jim Frank
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic