最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论