• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Remove unwanted double quote from .csv file

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I have a .csv file like this:

Field1,Field2
My Name is,"My ""Pet"" Name is"

When a split form (,) the string i get following in text file
Field1,Field2
"My Name is", """My """"Pet"""" Doe"""

I want to get output same as the input.
Any buddy please help me.

Thanks in Advance.
Sunil
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String.split() does not add quotes as far as I know. So it looks like you got the extra quotes somewhere else. Please post exactly what you're doing (and use code tags ;)
 
Sunil Nagotra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Thanks for reply

Hi

I have .csv file which have some record with double code.

Like

My Name is,"My ""Pet"" Name is"

I want to write its contents into a text file
the contents of generated file show extra double code.

output files show

"My Name is","""My """"Pet"""" Name is"""

I am using following code.


Excepted output will be

"My Name is",""My ""Pet"" Name is""

Thanks,
Sunil


>
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're better off using a CSV library (such as the ones mentioned in the AccessingFileFormats page) that know when to add and when to remove the double quotes.
 
Marshal
Posts: 75653
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please always use the code button. Since you are new, I have edited your post and you can see how much better it looks. Also always use spaces for indentation, not tabs.
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something's still missing in there. You're reading an entire line with the BufferedReader.readLine(). This method does not add extra quotes. Print out the input line after reading it, it should look exactly like in the .csv file.

Then you split the line. That method also doesn't add quotes. Print out each token, you should get two tokens:
1) My Name is
2) "My ""Pet"" Name is"

Then you write the tokens. FileWriter also doesn't add quotes. Note that you are writing a comma after each token, that should appear in your output as well (also after the last token!)...it doesn't, so either you're using another method than you think you do, or something else is amiss here.
 
Sunil Nagotra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I still Have same problem
I have attached csv file
following code used to display the output but still getting same output.
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not following; are you saying that this piece of code produces different output than you get if you open the file in a text editor (NOT a spreadsheet application)?
 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic