This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unwanted newlines when reading from a csv.

 
Steve Swanson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I'm doing coding a simple little app that reads from a .csv file, saves the fields to some properties in java beans (one bean per row in the .csv). Each bean (or row) is then added to a list. Obviously I will do something more interesting with this list down the road, but I've run into a problem.

Some of the fields in the .csv have newline characters in them which are carrying over to the fields in the java beans. I do not want newline characters in my bean fields, but I can't seem to figure out how to eliminate them. The .csv file was created from an Excel spreadsheet in which newlines in fields were acceptable.

Isn't there some kind of String manipulation trick that will eliminate the newlines? In notepad the newline character is represented as one of those wonderful little box characters, and that's the character we need to dispose of. Thanks for helping me jog my memory!

--Steve
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would a myString.replace("\n","") not work?
[ December 18, 2006: Message edited by: Edwin Dalorzo ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CSV has a number of complications that aren't obvious at first. If you use a library like Ostermiller Utils you won't have to worry about those.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!