JB88
JB88

Reputation: 37

How to write two comma seperated values as one value

I am retrieving the values using regular expression in jmeter and writing those values into a csv file.But one of my value returns values as (value1,value2), how can i add write those 2 values as one value in csv file.Below is my code

String statusvar = vars.get("guid");
String guidstat = vars.get("guidn");
String custstat = vars.get("custType");


String fpath = vars.get("write_file_path");

String newStatus;

 FileWriter fstream = new FileWriter(fpath+"new_record.csv", false);

 BufferedWriter out = new BufferedWriter(fstream);


 out.write(statusvar+","+guidstat+","+custstat);
 out.newLine();
 out.flush();

Upvotes: 0

Views: 77

Answers (1)

Jeronimo Backes
Jeronimo Backes

Reputation: 6289

Write your values within quotes and it should be OK. If a value contains quotes, then you'd need to escape them. Just replace each " by "", so value"a,valueB is written as "value""a,valueB"

If this becomes too tricky then I suggest getting a CSV parsing/writing library to do the job for you such as univocity-parsers - I'm the author of this one by the way.

Upvotes: 1

Related Questions