如果将值括在双引号中,如何分割忽略的逗号。
可获得的数据:
3545年,Albert,“Mathias Albert,Lars-Erik Cederman和Alexander Wendt (编)”,2010
应该分成一个数组:
arr(0) = "3545"
arr(1) = "Mathias Albert, Lars-Erik Cederman and Alexander Wendt (eds)"
arr(2) = "2010"
答案 0 :(得分:2)
虽然从长远来看使用ADO文本驱动程序可能是最好的方法,但您可以使用特定/自定义的RegExp进行快速和快速操作。脏'只使用一次'脚本:
>> Set r = New RegExp
>> r.Pattern = "^([^,]+),([^,]+),""([^""]+)"",(.+)$"
>> s = "3545,Albert,""Mathias Albert, Lars-Erik Cederman and Alexander Wendt (eds)"",2010"
>> Set m = r.Execute(s)
>> ReDim a(3)
>> For i = 0 To UBound(a)
>> a(i) = m(0).SubMatches(i)
>> Next
>> WScript.Echo Join(a, vbCrLf)
>>
3545
Albert
Mathias Albert, Lars-Erik Cederman and Alexander Wendt (eds)
2010
>>
为了应对空白字段,.Pattern需要进一步摆弄。
如果您更喜欢Split()
,请执行以下操作:
>> s = "3545,Albert,""Mathias Albert, Lars-Erik Cederman and Alexander Wendt (eds)"",2010"
>> ReDim a(3)
>> q = Split(s, """")
>> WScript.Echo Join(q, vbCrLf)
>>
3545,Albert,
Mathias Albert, Lars-Erik Cederman and Alexander Wendt (eds)
,2010
>> c = Split(q(0), ",")
>> WScript.Echo Join(c, vbCrLf)
>>
3545
Albert
>> a(0) = c(0)
>> a(1) = c(1)
>> a(2) = q(1)
>> a(3) = Mid(q(2), 2)
>> WScript.Echo Join(a, vbCrLf)
>>
3545
Albert
Mathias Albert, Lars-Erik Cederman and Alexander Wendt (eds)
2010
>>
应该让你入门。