解析CSV,忽视了内部字符串逗号VBA? [英] Parse CSV, ignoring commas inside string literals in VBA?

查看:525
本文介绍了解析CSV,忽视了内部字符串逗号VBA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有运行,每天将VBA应用程序。它检查其中的CSV自动下载的文件夹,其含量增加了的数据库。在分析他们,我意识到,某些值有逗号作为其名称的一部分。这些数值均包含在字符串。

I have a VBA application that runs every day. It checks a folder where CSVs are downloaded automatically, and adds their contents to a database. When parsing them, I realized that certain values had commas as a part of their name. These values were contained in string literals.

所以我试图找出如何解析这个CSV和忽视中包含的字符串的逗号。例如...

So I'm trying to figure out how to parse this CSV and ignore commas that are contained in string literals. For example...

1,2,3,"This should,be one part",5,6,7 Should return 

1
2
3
"This should,be one part"
5
6
7

我一直使用VBA的分裂()函数,因为我不想重新发明轮子,但如果我有我想我会做其他的事情。

I have been using VBA's split() function, because I don't wanna reinvent the wheel, but if I have to I guess I'll do something else.

任何建议将是AP preciated。

Any suggestions would be appreciated.

推荐答案

一个简单的正则表达式解析CSV行,假设没有引号里引用的字段,方法是:

A simple regex for parsing a CSV line, assuming no quotes inside quoted fields, is:

"[^"]*"|[^,]*

每场比赛将返回一个字段。

Each match will return a field.

这篇关于解析CSV,忽视了内部字符串逗号VBA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆