SplitTbl – Split a string with multiple delimiters

SplitTbl – Split a string with multiple delimiters

' A variant of the Split function, that offers the following improvements'   You can pass a list of valid delimiters to the second argument'   (however, only single-char delimiters are accepted)'   Differently from the regular Split function, consecutive occurrences'   of delimiters are ignored (in this case Split creates empty'   elements in the result array)Function SplitTbl(Text As String, Optional DelimiterTbl As String = " ") As _    String()    Dim index As Long, startIndex As Long    Dim itemCount As Long    ReDim result(10) As String        For index = 1 To Len(Text)        If InStr(DelimiterTbl, Mid$(Text, index, 1)) Then            ' we've found a delimiter            If startIndex Then                ' if we're inside an item, store it in the result array                If itemCount > UBound(result) Then                    ' make room in the array, if needed                    ReDim Preserve result(itemCount + 10) As String                End If                result(itemCount) = Mid$(Text, startIndex, index - startIndex)                itemCount = itemCount + 1                startIndex = 0            End If        Else            ' this is not a delimiter            If startIndex = 0 Then                ' if we aren't in the middle of an item,                ' mark the beginning of this new element                startIndex = index            End If        End If    Next        ' process the last word    If startIndex Then        ' if we're inside an item, store it in the result array        If itemCount > UBound(result) Then            ' make room in the array, if needed            ReDim Preserve result(itemCount + 10) As String        End If        result(itemCount) = Mid$(Text, startIndex, index - startIndex)        itemCount = itemCount + 1    End If    If itemCount > 0 Then        ' assign the result only if there is at least on item        ReDim Preserve result(itemCount - 1) As String        SplitTbl = result()    Else        ' this returns the type of uninitialized array that        ' would be returned by the Split function        SplitTbl = Split("")    End IfEnd Function

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes