|
|
|
|
|
Dicas
|
|
Visual Basic (Datas/Números/Strings)
|
|
|
Título da Dica: Fazendo um Token no VB
|
|
|
|
Postada em 3/2/2003 por Felipe
no general declarations: 'Declare :Function GetToken(ByVal strVal As String, intIndex As Integer, _ ' strDelimiter As String) As String
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
exemplo: GetToken("steve@hotmail.com", 2, "@") retorna "hotmail.com" GetToken("123-45-6789", 2, "-") retorna "45" GetToken("first,middle,last", 3, ",") retorna "last"
|
|
|
|
|