A recent PHP Script was posted which contained "ports" of the token functions from mIRC which can be very helpful
So, i gave it a go in VB.NET Starting off with GetTok(), i've attempted to include all of the sub functions too, including negative tokens, and ranges.
I'll start working on the others such as AddTok() etc.
Not sure if this is the efficient method. Any other ideas, give me a shout :)
Public Function GetTok(ByVal Str As String, ByVal Token As String, ByVal Delimiter As Short)
' Syntax: GetTok(String, ([Negative]Token)|(Token[-RangeToken]), Delimiter)
' Example: GetTok("This is my string", "3", 32)
' returns - "my"
' Example: GetTok("This is my string", "-1", 32)
' returns - "string"
' Example: GetTok("This is my string", "2-3", 32)
' -------------------------------------------
If Str Is String.Empty Then
Return "Error, Empty string"
ElseIf Delimiter < 1 Or Delimiter > 255 Then
Return "Error, Delimiter must be between 1-255"
Else
Dim CheckRgx As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("^(\d+)-(\d*)$")
If CheckRgx.IsMatch(Token) Then
Dim SplitArray() As String = Split(Str, Chr(Delimiter)), Returnex As String = ""
Dim Range() As String = CheckRgx.Split(Token)
For Index As Integer = Range(1) To Range(2)
Returnex += IIf(Returnex IsNot String.Empty, Chr(Delimiter), "") & SplitArray(Index - 1)
Next
Return Returnex
Else
If Token = 0 Then
Return "Error, token cannot be = 0"
ElseIf Token > 0 Then
Dim SplitArray() As String = Split(Str, Chr(Delimiter))
Return SplitArray(Token - 1)
ElseIf Token < 0 Then
Dim SplitArray() As String = Split(Str, Chr(Delimiter))
Return SplitArray(SplitArray.Length + Token)
End If
End If
End If
End Function