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

Remove unwanted chars (new line,tab) in java

 
sujith delpachithra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using informix server as my database. i have some data in it with dirty values like new line chars,tab chars etc.

i want to remove those from my database.

Please, reply.
 
Arka Guhathakurta
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
copy the content to a string variable and then use trim method to remove unwanted spaces from either side of the string.
Note that trim will not remove whitespace chars inside the string between words.
I hope it helps.
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to remove the spaces from the middle of the string too, you can use the replaceAll method of String class with a regex like \s to replace all the space characters with anything that you like. This method would be a little slow if you want to update all the records. You should try a bulk update query specific to your database to achieve that...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic