VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Function retrives info between 2 delimiters, or the whole string.

by Rick (1 Submission)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 14th November 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Function retrives info between 2 delimiters, or the whole string.

Rate Function retrives info between 2 delimiters, or the whole string.



Private Function ParseString(strRecieved As String, strDelimiter As String, intStart As Integer, _            
intStop As Integer) As String                                                                                 
'parse the string, get the info between 2 delimiters                                                          
'use '0' to start at the beginning of the string, (not the 1st delimiter)                                       
'use the last delimiter number +1 to get the end of the string                                                       

                                                                                                              
  Dim x As Integer                                                                                            
  Dim DelimiterLocArray() As String                                                                           
  Dim intCounter As Integer                                                                                   
                                                                                                              
    ReDim DelimiterLocArray(0)                                                                                
    DelimiterLocArray(0) = "0"                                                                                
                                                                                                              
    For x = 1 To Len(strRecieved)                                                                             
      If Mid$(strRecieved, x, 1) = strDelimiter Then                                                          
        intCounter = intCounter + 1                                                                           
        ReDim Preserve DelimiterLocArray(intCounter)                                                          
        DelimiterLocArray(intCounter) = x                                                                     
      End If                                                                                                  
    Next x                                                                                                    
                                                                                                              
    ReDim Preserve DelimiterLocArray(UBound(DelimiterLocArray) + 1)                                           
    DelimiterLocArray(UBound(DelimiterLocArray)) = Len(strRecieved) + 1                                       
                                                                                                              
    ParseString = Mid$(strRecieved, CInt(DelimiterLocArray(intStart)) + 1, CInt(DelimiterLocArray(intStop) _  
     - 1 - CInt(DelimiterLocArray(intStart))))                                                                
                                                                                                              
    Erase DelimiterLocArray                                                                                   
End Function                                                                                                  
                                                                                                              
strResult = ParseString("this is the time", " ", 0, 1)                                                        
strResult = ParseString("this is the time", " ", 3, 4)                                                        


Download this snippet    Add to My Saved Code

Function retrives info between 2 delimiters, or the whole string. Comments

No comments have been posted about Function retrives info between 2 delimiters, or the whole string.. Why not be the first to post a comment about Function retrives info between 2 delimiters, or the whole string..

Post your comment

Subject:
Message:
0/1000 characters