On Sat, May 3, 2014 at 2:00 AM, SK <skrishna...@gmail.com> wrote:
> 1) I have a csv file where one of the field has integer data but it appears
> as strings: "1", "3" etc. I tried using toInt to implcitly  convert the
> strings to int after reading (field(3).toInt). But I got a
> NumberFormatException. So I defined my own conversion
> as follows, but I still get a NumberFormatException - the toInt function on
> StringOps is failing. Any idea, how I can convert strings to int?

toInt certainly works, and you need not write your own conversion,
but, a string with double-quotes is not a valid number. To be safest,
you might write an "unquote" function that strips quotes if they
exist, rather than just remove all quotes in the string. (Or see above
using a Java library that specializes in handling all the details of
CSV, including quoted and escaped fields -- I liked SuperCSV.)

Reply via email to