Reputation: 845
I am working on a java project. I have to retain a comma separator from my parsed string "," and still should be able to write into csv file. currently my csv file values are separated with comma (",") in it . because of this , if I have comma in a string its divided into two string on csv
ex:
input string : "Animal","Stand","Earth","owner,jeff"
my current output : (which is incorrect )
Expected output :
I have the logic in place for writing things into csv , I just need the string to be manipulated in a such way it should in corporate the ",". how to achieve this ?
here is my code:
private static void Addrow(String Animals, String Posture, String planet,String owner) throws IOException {
String csv_write = csv_file_to_write;
CSVWriter writer = new CSVWriter(new FileWriter(csv_write , true));
String [] record = (Animals+","+Posture+","+planet+","+owner).split(",");
writer.writeNext(record);
writer.close();
}
Upvotes: 0
Views: 789
Reputation: 21
One way to tackle that would be to split it at \",\"
and for the first entry remove the "
at the beginning and for the last entry remove the "
at the end. You will then be left with the list of strings Animal
, Stand
, Earth
, Owner,Jeff
and so on...
Upvotes: 1