我在 Adobe 的 ExtendScript 中解析 Vimeo 评论页面格式的 CSV 时遇到问题。问题是 ExtendScript 基于 ES3 并且大多数解决方案似乎都不起作用,因为它们基于现代 JS。
此外,CSV 有一个标题行、末尾的空行、一些但不是所有字段(我想删除)的双引号以及字段中潜在的换行符和特殊字符(包括逗号)。有没有办法得到一个“干净的”二维数组?
我在这里尝试过解决方案:解析 CSV 数据的 Javascript 代码 在 这里:如何使用 Javascript 解析 CSV 字符串,其中包含数据中的逗号?
但无法让它们工作,我认为这些问题与 ExtendScript 过时有关。
CSV 文件
"Test Video-01.mp4",1,00:00:00,AVT,"test comment 1",--,"Tuesday, July 9, 2019 At 8:49 AM",No
"Test Video-01.mp4",2,00:00:00,AVT,"another at same timecode",--,"Tuesday, July 9, 2019 At 8:50 AM",Yes
,3,00:00:00,--,"another at same timecode","reply here from anon","Tuesday, July 9, 2019 At 8:54 AM",Yes
"Test Video-01.mp4",3,00:00:11,AVT,"really long comment Lorem ipsum dolor sit amet, Purus sit amet volutpat consequat mauris nunc congue nisi. Semper viverra nam libero justo laoreet sit amet cursus. Id interdum velit laoreet id. Bibendum est ultricies integer quis auctor elit sed vulputate. And some special chars to boot: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
Eros donec ac odio tempor orci dapibus. Nam libero justo laoreet sit amet. Pellentesque pulvinar pellentesque habitant morbi. Pellentesque eu tincidunt tortor aliquam nulla facilisi cras fermentum.",--,"Tuesday, July 9, 2019 At 8:50 AM",No
"Test Video-01.mp4",4,00:00:19,AVT,"another one different timecode",--,"Tuesday, July 9, 2019 At 8:50 AM",Yes
"Test Video-01.mp4",5,00:00:43,AVT,"comment here tooo",--,"Tuesday, July 9, 2019 At 8:51 AM",No
,6,00:00:43,AVT,"comment here tooo","reply to a comment","Tuesday, July 9, 2019 At 8:51 AM",No
,7,00:00:43,AVT,"comment here tooo","reply again","Tuesday, July 9, 2019 At 8:51 AM",No
,8,00:00:43,"PJ Palomaki","comment here tooo","Different person reply","Tuesday, July 9, 2019 At 8:52 AM",No
,9,00:00:43,--,"comment here tooo","Anon reply reply","Tuesday, July 9, 2019 At 8:53 AM",No
"Test Video-01.mp4",6,00:01:29,--,"Anon comment",--,"Tuesday, July 9, 2019 At 8:53 AM",No
,7,00:01:29,--,"Anon comment","Anon reply","Tuesday, July 9, 2019 At 8:53 AM",No
,,,,,,,
如果我用 解析split("\n")
,带有换行符的字段会被拆分。如果我使用split(",")
任何带逗号的字段,则会被拆分。
另外,我想将解析函数包含在内(在主脚本中,而不是加载外部脚本),因为我更喜欢在部署时使用单个文件。
谢谢,PJ