0

如果值被双引号括起来,如何拆分忽略的逗号。

可用数据:

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"
4

1 回答 1

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
>>

应该让你开始。

于 2012-10-12T09:58:28.007 回答