forger Posted April 6, 2006 Share Posted April 6, 2006 Ok, I searched "Scripts and Scraps" and found nothing for token. Maybe it's done with a different name. Anyway, it's nothing fancy really, but it eases up my work with text strings:) I was used to mirc scripting, so I made something similar to it! I made the first two functions without arrays, maybe worthless, just playing around a bit Hope it's useful to you, as it is to me! P.S. Don't be strict I'm still learning heh. expandcollapse popup#include <array.au3> #include <Misc.au3> ; _GetFirstTok: Get the first token of the string $_SearchStr separated by character $_Chr ; If $_Chr is number, it is converted to a character equivalent. ; Needs Misc.au3 for _Iif; No array usage; Breaks on first found $_Chr Func _GetFirstTok($_SearchStr,$_Chr) Local $_ChrCheck = _Iif(IsNumber($_Chr),Chr($_Chr),$_Chr),$a = 1 While StringMid($_SearchStr,$a,1) If StringMid($_SearchStr,$a,1) = $_ChrCheck Then Return StringLeft($_SearchStr,Number($a - 1)) EndIf $a = $a + 1 WEnd EndFunc ; _GetLastTok: Get the last token of the string $_SearchStr separated by character $_Chr ; If $_Chr is number, it is converted to a character equivalent. ; Needs Misc.au3 for _Iif; No array usage Func _GetLastTok($_SearchStr,$_Chr) Local $_ChrCheck = _Iif(IsNumber($_Chr),Chr($_Chr),$_Chr),$a = 1 While StringMid($_SearchStr,$a,1) If StringMid($_SearchStr,$a,1) = $_ChrCheck Then Local $_LastPos = $a EndIf $a = $a + 1 WEnd Local $_Total = $a - 1, $_LastTok = StringRight($_SearchStr,Number($_Total - $_LastPos)) Return $_LastTok EndFunc ; _IsTok: Checks if token $_Tok is a token of string $_TokList (separated by character/character number $_Chr) ;Reply: Boolean 0 and 1 for False and True respectively ;Needs Misc.au3 for _Iif and Array.au3 for _ArraySearch Func _IsTok($_TokList,$_Tok,$_Chr) Local $_ChrCheck = _Iif(IsNumber($_Chr),Chr($_Chr),$_Chr) Local $_List = StringSplit($_TokList,$_ChrCheck) If _ArraySearch($_List,$_Tok) = -1 Then Return 0 Else Return 1 EndIf EndFunc ; _CountTok: Counts the tokens in string $_TokList separated by character/character number $_Chr ; If $_Chr is number, it is converted to a character equivalent. ; Needs Misc.au3 for _Iif Func _CountTok($_TokList,$_Chr) Local $_ChrCheck = _Iif(IsNumber($_Chr),Chr($_Chr),$_Chr) Dim $_List = StringSplit($_TokList,$_ChrCheck) Return $_List[0] EndFunc ; _GetTok: Get the Nth($_TokNum) token from string $_TokList separated by character/character number $_Chr ; If $_Chr is number, it is converted to a character equivalent. ; Needs Misc.au3 for _Iif Func _GetTok($_TokList,$_TokNum,$_ChrMatch) Local $_ChrCheck = _Iif(IsNumber($_ChrMatch),Chr($_ChrMatch),$_ChrMatch) Dim $a = 0, $_List = StringSplit($_TokList,$_ChrCheck) Return $_List[$_TokNum] EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now