Advertisement
ASP_Volume3 String Manipulation #44626

GetToken

The following code is a Visual Basic function that returns a specific "token" (section/substring of data) from a delimited string list. The function accepts the index of the desired token and also the delimiter as specified by the programmer.

AI

Ringkasan AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kode Sumber
original-source
Function GetToken(ByVal strVal As String, intIndex As Integer, _
	strDelimiter As String) As String
'------------------------------------------------------------------------
' Author  : Troy DeMonbreun ([email protected])
'
' Returns : [string] "Token" (section of data) from a list of
'      delimited string data
'
' Requires : [string] delimited data,
'      [integer] index of desired section,
'      [string] delimiter (1 or more chars)
'
' Examples : GetToken("[email protected]", 2, "@") returns "hotmail.com"
'      GetToken("123-45-6789", 2, "-") returns "45"
'      GetToken("first,middle,last", 3, ",") returns "last"
'
' Revised : 12/22/1998
'------------------------------------------------------------------------
	Dim strSubString() As String
	Dim intIndex2 As Integer
	Dim i As Integer
	Dim intDelimitLen As Integer
	intIndex2 = 1
	i = 0
	intDelimitLen = Len(strDelimiter)
	Do While intIndex2 > 0
  
		ReDim Preserve strSubString(i + 1)
    
		intIndex2 = InStr(1, strVal, strDelimiter)
  
		If intIndex2 > 0 Then
			strSubString(i) = Mid(strVal, 1, (intIndex2 - 1))
			strVal = Mid(strVal, (intIndex2 + intDelimitLen), Len(strVal))
		Else
			strSubString(i) = strVal
		End If
    
		i = i + 1
    
	Loop
	If intIndex > (i + 1) Or intIndex < 1 Then
		GetToken = ""
	Else
		GetToken = strSubString(intIndex - 1)
	End If
End Function
Komentar Asli (3)
Dipulihkan dari Wayback Machine