VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Easy Tokenizer

by Paul Crowdy (4 Submissions)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

Break up variables in a string, whatever separator is used.

Inputs
String to be Tokenized, Separator between variables
Code Returns
List of individual variables
API Declarations
Public Type TokenList
Tokens() As String
TokenCount As Integer
End Type
Public Function Tokenize(strString As String, strSeparator As String) As TokenList

Dim iCount As Integer
Dim iStart As Integer
Dim iTokens As Integer
ReDim Tokenize.Tokens(0)
iTokens = 0
iCount = 1
iStart = 1

Do Until iCount = Len(strString)

If Mid$(strString, iCount, Len(strSeparator)) = strSeparator Then
ReDim Preserve Tokenize.Tokens(iTokens + 1)
Tokenize.Tokens(iTokens) = Mid$(strString, iStart, iCount - iStart)
iStart = iCount + Len(strSeparator)
iTokens = iTokens + 1
End If

iCount = iCount + 1

Loop

Tokenize.Tokens(iTokens) = Mid$(strString, iStart)
Tokenize.TokenCount = iTokens + 1

End Function

Rate Easy Tokenizer

Private Sub Form_Load()
  Dim tk As TokenList
  Dim strTest As String
  Dim strSeparator As String
  
  strTest = "String, Tokenization, By, Paul, Crowdy, www.kmcpartnership.co.uk"
  strSeparator = ", "
  
  tk = Tokenize(strTest, strSeparator)
  For i = 0 To tk.TokenCount - 1
    MsgBox "Token " & i + 1 & " = " & tk.Tokens(i), vbInformation, strTest
  Next i
  End
End Sub

Download this snippet    Add to My Saved Code

Easy Tokenizer Comments

No comments have been posted about Easy Tokenizer. Why not be the first to post a comment about Easy Tokenizer.

Post your comment

Subject:
Message:
0/1000 characters