I'm trying to find a better solution for the integration of a string and generate a new field with the maximum value of the parameter. @AutomatedChaos has helped me with the following code. But I need a better solution for the flexibility of the code.
First string split by *
(stars) and I want to merge all items and create a new string with max value.
fString = "projects@dnProjectsPatterning=0|dnProjectsSendReport=1#workplans@dnWorkplansAdd=0|dnWorkplansGrouping=1*projects@dnProjectsPatterning=1|dnProjectsSendReport=3#workplans@dnWorkplansAdd=1|dnWorkplansGrouping=0*projects@dnProjectsPatterning=5|dnProjectsSendReport=1#workplans@dnWorkplansAdd=0|dnWorkplansGrouping=2"
Set dict = CreateObject("Scripting.Dictionary")
Set re = New RegExp
re.Global = True
re.Pattern = "(\w+)=(\d+)"
Set matches = re.Execute(fString)
For Each match In matches
key = match.Submatches(0)
value = CInt(match.Submatches(1))
If dict.Exists(key) Then
If value < dict.Item(key) then
value = dict.Item(key)
End If
End If
dict.Item(key) = value
Next
For Each key In dict
MsgBox key & "=" & dict.Item(key)
Next
' output:
' dnProjectsPatterning=5
' dnProjectsSendReport=3
' dnWorkplansAdd=1
' dnWorkplansGrouping=2
I want to generate this string:
newString = "projects@dnProjectsPatterning=5|dnProjectsSendReport=3#workplans@dnWorkplansAdd=1|dnWorkplansGrouping=2"
Please note for projects@
and workplans@
, the two are split by #
.