This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
D. Ogranos
Ranch Hand
Joined: Feb 02, 2009
Posts: 210
posted
0
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
Joined: Apr 13, 2011
Posts: 6
posted
0
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
>
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
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.
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
Joined: Feb 02, 2009
Posts: 210
posted
0
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
Joined: Apr 13, 2011
Posts: 6
posted
0
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
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
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)?
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Remove unwanted double quote from .csv file