Remove duplicates in string 追蹤

0
Avatar
Erwin Chu

I have a field that sometimes returns duplicates values (i.e. "Bb AA dD CC CC ff") 

How do I create a vb script to help me remove the duplicate and rejoin (i.e. "Bb AA dD CC ff")?

2 意見

0
Avatar
KM3
評論操作 永久連結

You can (probably) do this using regular expression (RegEx). However, I'm not skilled enough that I could simply provide the code for it, however, it's actually not too complicated and you can probably figure it out on your own - start reading up here: https://msdn.microsoft.com/en-us/library/6wzad2b2(v=vs.84).aspx

Essentially, you're trying to match two identical characters followed by a space but only, when followed by another pair of those identical characters. You need to figure out what's called the "Pattern", to match this scenario, then let RegEx "do the rest"

0
Avatar
Erwin Chu
評論操作 永久連結

Thanks for your input KM3

I was actually able to find a script and modify it for my needs.

Dim varSection
Dim sTemp
sDelimiter = " "
For Each varSection In Split(Value, sDelimiter)
If InStr(1, sDelimiter & sTemp & sDelimiter, sDelimiter & varSection & sDelimiter, vbBinaryCompare) = 0 Then
sTemp = sTemp & sDelimiter & varSection
End If
Next

Value = Mid(sTemp, Len(sDelimiter) + 1)

登入寫評論。