VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A simple function to get everything between two delimiters. The result is return in an array

by Gilles Manouvrier (3 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sat 1st December 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

A simple function to get everything between two delimiters. The result is return in an array

Rate A simple function to get everything between two delimiters. The result is return in an array



dim rs() as string
'if you have a string like tom="this is 'a test ' in order to'test'

'the function syntaxe'll be 
'rs=Delimiter(tom,"'","'") if you want to get everything between the "'"


Private Function Delimiter(ByVal texte As String, ByVal delimiter1 As String, ByVal delimiter2 As String) As Variant
    'fonction de récupération  de chaine entre deux bornes délimitrices
    'retour sous forme de tableau de string
    Dim interne() As String
    Dim cpt As Integer
    Dim Flag1 As Boolean
    Dim flag2 As Boolean
    
    ReDim Preserve interne(1) 'initialisation  du tableau à 1
    
    qte = 1 'le premier composant du tableau en sortie aura l'index 1
    Do While cpt < Len(texte)
        cpt = cpt + 1
        'ReDim Preserve interne(cpt + 1) As String
        Debug.Print Mid$(texte, cpt, 1)
        If Mid$(texte, cpt, 1) = delimiter1 And Not Flag1 Then
            Flag1 = True
            GoTo lenext
        End If
        If Mid$(texte, cpt, 1) = delimiter2 And Flag1 = True Then
            Flag1 = False
            flag2 = True
            qte = qte + 1
            ReDim Preserve interne(qte + 1)
            GoTo lenext
        End If
        
        If Flag1 Then interne(qte) = interne(qte) & Mid$(texte, cpt, 1)
        

lenext:
    Loop
    
    Delimiter = interne
End Function



Download this snippet    Add to My Saved Code

A simple function to get everything between two delimiters. The result is return in an array Comments

No comments have been posted about A simple function to get everything between two delimiters. The result is return in an array. Why not be the first to post a comment about A simple function to get everything between two delimiters. The result is return in an array.

Post your comment

Subject:
Message:
0/1000 characters