javascript - How to write a value that contains a comma to a csv file? - Stack Overflow

I have a javascript program to write values to a csv file.I have a value that includes ma within.How

I have a javascript program to write values to a csv file. I have a value that includes ma within. How to do this? I am newbie to javascript. can you please help me?

I tried double quotes

content += record.number +","+ record.category +","+ record.status +","+ record.approval_status +","+ record.requested_by +","+ record.assigned_to +","+record.assign_dept +","+ record.coordinator +","+ record.coord_phone +","+ record.planned_start +","+ record.planned_end +","+record.reason +","+ record.risk_assessment +","+ record.logical_name +","+ "record.assets" +","+ record.request_date +","+ record.subcategory +","+ record.priority_code +","+ record.impact +","+  record.sched_outage_start +","+ record.sched_outage_end  + "\n";

record.assets is the field that will have ma within.

I have a javascript program to write values to a csv file. I have a value that includes ma within. How to do this? I am newbie to javascript. can you please help me?

I tried double quotes

content += record.number +","+ record.category +","+ record.status +","+ record.approval_status +","+ record.requested_by +","+ record.assigned_to +","+record.assign_dept +","+ record.coordinator +","+ record.coord_phone +","+ record.planned_start +","+ record.planned_end +","+record.reason +","+ record.risk_assessment +","+ record.logical_name +","+ "record.assets" +","+ record.request_date +","+ record.subcategory +","+ record.priority_code +","+ record.impact +","+  record.sched_outage_start +","+ record.sched_outage_end  + "\n";

record.assets is the field that will have ma within.

Share Improve this question edited Jun 10, 2022 at 13:43 Vadim Kotov 8,2848 gold badges50 silver badges63 bronze badges asked Mar 3, 2014 at 10:25 user1407668user1407668 6175 gold badges21 silver badges35 bronze badges 2
  • Just quote delimit your columns in your CSV output. – user3358344 Commented Mar 3, 2014 at 10:26
  • try this stackoverflow./questions/17836273/… – Aamir Afridi Commented Mar 3, 2014 at 10:28
Add a ment  | 

2 Answers 2

Reset to default 6

Close them in quotes and escape double quotes?

http://en.wikipedia/wiki/Comma-separated_values

1999,Chevy,"Venture ""Extended Edition""",4900.00

in your case:

"," + "record.assets" + ","

should be

"," + '"' + record.assets.replace(/"/g,'""') + '"' + ","

You can put your text between quotes.
You are not obliged to use a ma , you can use a ";" too (dutch/german format but works well)
--> http://en.wikipedia/wiki/Comma-separated_values
1997;Ford;E350;2,34

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745047936a4608209.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信