Reputation: 3030
I have searched the internet about the comma issues about csv document.But my trouble is about dealing with the value containing not only comma but also quote.
like String value = "FName,\"FName2,FName3";
I want to display the string FName,"FName2,FName3 in the csv document.Though i tried a couple of approaches,but failed.
When the string contains comma,I can use double quote to surround it like code below.
outBuff.append("\\").append(cellData).append("\\").append(",");
But when the string contains "" and , How can i deal with this issue?
I can only use the pulest java,and can not use the third part library. Thanks.
Upvotes: 0
Views: 2129
Reputation: 109
StringBuffer sbStudentData = new StringBuffer();
sbStudentData.append(",\"").append(LastName).append(",\"").append(FirstName)
it will work fine like Last name,First name.
Upvotes: 1
Reputation: 12296
Consider using os specialized CSV parser, like one from Apache Commons
It will handle most of corner cases for you
Upvotes: 1
Reputation: 1584
try enclosing your double quote with two double qoutes:
String value = "FName,\"\"\"FName2,FName3";
Upvotes: 0