VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



this SplitMod Function allows you to specify a second delimiter that will overlook the first delimi

by Adam Wilson (2 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 28th December 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

this SplitMod Function allows you to specify a second delimiter that will overlook the first delimiter if it is contained within. for example,

Rate this SplitMod Function allows you to specify a second delimiter that will overlook the first delimi



'this function is a modified version of the Split() function.  This version allows for
'items to be grouped within a secondary set of delimiters.  For example:
'
'testStr = "'Adam,Tanya,Larry',Emily,April,Cassandra,Laura,'apple,banana,pear'"
'
'testArray = SplitMod(testStr, ",", "'")
'    returns:
'testArray(0) = "Adam,Tanya,Larry"
'testArray(1) = "Emily"
'testArray(2) = "April"
'testArray(3) = "Cassandra"
'testArray(4) = "Laura"
'testArray(5) = "apple,banana,pear"

    On Error GoTo SplitModError

    'see if expression is null
    Dim strExpression As String
    strExpression = Trim(strInitExpression)
    
    'see if expression is blank
    If (Len(strExpression) < 0) Then
        SplitMod = Null
        Exit Function
    End If


    If Not InStr(strExpression, strGroupingDelimiter) > 0 Then
        'grouping delimiter doesn't appear, so just use regular "Split" function
        SplitMod = Split(strExpression, strDelimiter)
        
        Exit Function
    End If
        
        
    'grouping delimiter
    Dim retArray() As String
    Dim position As Integer, ArraySize As Integer
    
    ArraySize = 1

    Do While Len(strExpression) > 0
        ReDim Preserve retArray(ArraySize - 1)
    
        'see if we begin with a groupDelimiter
        If (Left(strExpression, 1) = strGroupingDelimiter) Then

            'get the first item
            position = InStr(2, strExpression, strGroupingDelimiter)
            
            If (position < 1) Then
                'no ending groupDelimiter tag, so assume to take the rest of the string
                retArray(ArraySize - 1) = Trim(Mid(strExpression, 2, Len(strExpression) - 1))
                strExpression = ""
            Else
                retArray(ArraySize - 1) = Trim(Mid(strExpression, 2, position - 2))
                strExpression = Trim(Mid(strExpression, position + 2))
            End If

        Else
            'just a regular item
            position = InStr(strExpression, strDelimiter)
            
            If (position < 1) Then
                'no ending delimiter, so assume to take the rest of the string
                retArray(ArraySize - 1) = Trim(strExpression)
                strExpression = ""
            Else
                retArray(ArraySize - 1) = Trim(Left(strExpression, position - 1))
                strExpression = Trim(Mid(strExpression, position + 1))
            End If
            
        End If
        
        ArraySize = ArraySize + 1
        
    Loop
    
    SplitMod = retArray
    Exit Function

SplitModError:
    SplitMod = Null

End Function        'SplitMod


Download this snippet    Add to My Saved Code

this SplitMod Function allows you to specify a second delimiter that will overlook the first delimi Comments

No comments have been posted about this SplitMod Function allows you to specify a second delimiter that will overlook the first delimi. Why not be the first to post a comment about this SplitMod Function allows you to specify a second delimiter that will overlook the first delimi.

Post your comment

Subject:
Message:
0/1000 characters