Sign in to follow this  
Followers 0
Quual

Token Based Functions - Anyone Bored ?

1 post in this topic

I am currently scripting a few applications that call for a lot of string manipulation. Long ago I did a fair amount in the mIRC scripting language and there was a set of token commands that were extremely useful. I truly miss them... If I had time I would recreate them myself... but alas the clock just moves to fast.

If anyone wants to create an include for them I would be grateful. To explain what the commands are and how they work, I made this include sheet.

....Its just empty functions and remarks...

#include-once

; #INDEX# ====================================================================================================

===================
; Title .........: Tokens
; AutoIt Version: 3.2.3++
; Language:    English
; Description ...: A set of versatile token based string manipulation commands.

; addtok(sText,sToken,C) ................: Adds a token to the end of text but only if it's not already in text.
; deltok(sText,Num,C) ...................: Deletes the Nth token from text.
; findtok(sText,sToken,Num,C) ...........: Returns the position of the Nth matching token in text.
; gettok(sText,Num,C) ...................: Returns the Nth token in text.
; instok(sText,sToken,Num,C) ............: Inserts token into the Nth position in text, even if it already exists in text.
; istok(sText,sToken,C) .................: Returns true if token exists, otherwise returns false.
; matchtok(sToken,sText,Num,C) ..........: Returns tokens that contain the specified string.
; numtok(sText,C) .......................: Returns number of tokens in text.
; puttok(sText,sToken,Num,C) ............: Overwrites the Nth token in text with a new token.
; remtok(sText,sToken,Num,C) ............: Removes the Nth matching token from text. If N = 0, applies to all matching items.
; reptok(sText,sToken,sNewtoken,Num,C) ..: Replaces the Nth matching token in text with a new token. If N = 0, applies to all matching items.
; sorttok(sText,C,nra) ..................: Sorts the tokens in text.
; wildtok(sToken,sWildstring,Num,C) .....: Returns the Nth token that matches the wildcard string.


; ====================================================================================================

===========================


 Func addtok(sText,sToken,C)
;addtok(text,token,C)
;Adds a token to the end of text but only if it's not already in text.
;addtok(a.b.c,d,46)       returns a.b.c.d
;addtok(a.b.c.d,c,46)       returns a.b.c.d
;The C parameter is the ascii value of the character separating the tokens.
EndFunc

Func addtokcs(sText,sToken,C)
;Note: addtokcs() is the case-sensitive version.
EndFunc

 Func deltok(sText,Num,C)
;deltok(text,N-N2,C)
;Deletes the Nth token from text.
;deltok(a.b.c.d,3,46)         returns a.b.d
;deltok(a.b.c.d,2-3,46)     returns a.d
;You can specify a negative value for N.
EndFunc
 
 Func findtok(sText,sToken,Num,C)
;findtok(text,token,N,C)
;Returns the position of the Nth matching token in text.
;findtok(a.b.c.d,c,1,46)        returns 3
;findtok(a.b.c.d,e,1,46)        returns $null
;If you specify zero for N, it returns the total number of matching tokens.
EndFunc

 Func findtokcs(sText,sToken,Num,C)
;Note: findtokcs() is the case-sensitive version.
EndFunc

 Func gettok(sText,Num,C)
;gettok(text,N,C)
;Returns the Nth token in text.
;gettok(a.b.c.d.e,3,46)      returns c
;gettok(a.b.c.d.e,9,46)      returns $null
;You can also specify a range of tokens:
;gettok(a.b.c.d.e,2-,46)        returns 2nd token onwards b.c.d.e
;gettok(a.b.c.d.e,2-4,46)      returns tokens 2 through 4 b.c.d
;You can specify a negative value for N.
 EndFunc
 
 Func instok(sText,sToken,Num,C)
;instok(text,token,N,C)
;Inserts token into the Nth position in text, even if it already exists in text.
;instok(a.b.d,c,3,46)       returns a.b.c.d
;instok(a.b.d,c,9,46)       returns a.b.d.c
;You can specify a negative value for N.

Func istok(sText,sToken,C)
;istok(text,token,C)
;Returns true if token exists, otherwise returns false.
EndFunc

 Func instokcs(sText,sToken,Num,C)
;Note: istokcs() is the case-sensitive version.
EndFunc

 Func matchtok(sToken,sText,Num,C)
;matchtok(tokens,string,N,C)
;Returns tokens that contain the specified string.
;matchtok(one two three, e, 0, 32) returns 2
;matchtok(one two three, e, 2, 32) returns three
;If you specify zero for N, it returns the total number of matching tokens.
EndFunc

 Func matchtokcs(sToken,sText,Num,C)
;Note: matchtokcs() is the case-sensitive version.
EndFunc

 Func numtok(sText,C)
;numtok(text,C)
;Returns number of tokens in text.
EndFunc

 Func puttok(sText,sToken,Num,C)
;puttok(text,token,N,C)
;Overwrites the Nth token in text with a new token.
;puttok(a.b.c.d,e,2,46)     returns a.e.c.d
;You can specify a negative value for N.
EndFunc
 
 Func remtok(sText,sToken,Num,C)
;remtok(text,token,N,C)
;Removes the Nth matching token from text. If N = 0, applies to all matching items.
;remtok(a.b.c.d,b,1,46)     returns a.c.d
;remtok(a.b.c.d,e,1,46)     returns a.b.c.d
;remtok(a.c.c.d,c,1,46)     returns a.c.d
EndFunc

Func remtokcs(sText,sToken,Num,C)
;Note: remtokcs() is the case-sensitive version.
EndFunc

 Func reptok(sText,sToken,sNewtoken,Num,C)
;reptok(text,token,new,N,C)
;Replaces the Nth matching token in text with a new token. If N = 0, applies to all matching items.
;reptok(a.b.c.d,b,e,1,46)       returns a.e.c.d
;reptok(a.b.c.d,f,e,1,46)       returns a.b.c.d
;reptok(a.b.a.c,a,e,2,46)       returns a.b.e.c
EndFunc


 Func reptokcs(sText,sToken,sNewtoken,Num,C)
;Note: reptokcs() is the case-sensitive version.
EndFunc

Func sorttok(sText,C,nra)
;sorttok(text,C,ncra)
;Sorts the tokens in text.
;sorttok(e.d.c.b.a,46)         returns a.b.c.d.e
;sorttok(1.3.5.2.4,46,nr)       returns 5.4.3.2.1
;The default is an alphabetic sort, however you can specify n = numeric sort, r = reverse sort, a = alphanumeric sort.
EndFunc

Func sorttokcs(sText,C,nra)
;Note: sorttokcs() is the case-sensitive version.
EndFunc


 Func wildtok(sTokens,sWildstring,Num,C)
;wildtok(tokens,wildstring,N,C)
;Returns the Nth token that matches the wildcard string.
;wildtok(one two three, t*, 0, 32) returns 2
;wildtok(one two three, t*e, 1, 32) returns three
;If you specify zero for N, it returns the total number of matching tokens.:
EndFunc

 Func wildtokcs(sTokens,sWildstring,Num,C)
; wildtokcs() is the case-sensitive version.
EndFunc

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0