vbscript 5. Populating array with specific text from string via start and end characters.


Example

'Note: I use this method to extract non-html data in extracted GET telnet results
'This example effectively grabs every other vehicle that have start and finish
'characters, which in this case is "/". 
'Resulting in an array like this:
'extractedData(0) = "/Jeep"
'extractedData(1) = "/Ford"
'extractedData(2) = "/Honda"


Dim combined : combined = Join(cars, "/") & "/" & Join(cars, "/")
'combined now equals Ford/Jeep/Honda/Ford/Jeep/Honda

Dim record, trigger : record = false : trigger = false
Dim extractedData() : ReDim extractedData(0)
For I = 1 to len(combined) 'searching the string one character at a time
    If trigger Then 'if I've already started recording values
        If Mid(combined, I, 1) = "/" Then 'End Character is found, stop recording
            record = false
            trigger = false
            ReDim Preserve extractedData(ubound(extractedData)+1) 'Prep next Array Entry
        End If
    Else
        If Mid(combined, I, 1) = "/" Then record = true 'Start recording on start character 
    End If
    If record Then 
        'Increment text on array entry until end variable is found. 
        extractedData(ubound(extractedData)) = extractedData(ubound(extractedData)) & Mid(combined, I, 1) 
        trigger = true
    End If
Next