Xibalba Posted July 22, 2010 Share Posted July 22, 2010 I want to loop through a string examining char by char, and take appropriate actions. Stuff I want to check is 'isNumeric', '== Chr("13")' and so forth.. How can I do this with some for-loop or such? Thx Link to comment Share on other sites More sharing options...
ALTIN Posted July 22, 2010 Share Posted July 22, 2010 have you seen StringInStr() function from help file? Link to comment Share on other sites More sharing options...
Xibalba Posted July 22, 2010 Author Share Posted July 22, 2010 (edited) Yeah, but that's not what i want. I think I'm on to something here, should be this simple: For $symbol In $string If [something] Then // Else // EndIf Next lol - Btw, what is "help file" ? I use the online docs as reference (coding in a non-SCiTe editor). Edited July 22, 2010 by Xibalba Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 22, 2010 Share Posted July 22, 2010 The AutoIt3.chm help file is the full language reference for AutoIt. The version posted to the web for online docs is usually out of date compared to the current version. The function you want is StringSplit(): $sInput = "A1B2C3" $aInput = StringSplit($sInput, "") For $n = 1 To $aInput[0] Select Case StringIsAlpha($aInput[$n]) MsgBox(64, "Alpha", "Letter = " & $aInput[$n], 3) Case StringIsInt($aInput[$n]) MsgBox(64, "Int", "Number = " & $aInput[$n], 3) EndSelect Next See help file for how it works. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
ALTIN Posted July 22, 2010 Share Posted July 22, 2010 (edited) This is what you need i think: $String = Stringsplit("XXXX-XXXX-XXXX-XXXX-XXXX", "") For $i = 1 to $String[0] Msgbox (0, "", $String[$i]) If($String[i] = Chr(13)) Then msgbox(0, "", "I found Enter char") Else ;something Else Endif Next Edit: lol, almost the same as PsaltyDS posted above Edited July 22, 2010 by ALTIN Link to comment Share on other sites More sharing options...
trancexx Posted July 22, 2010 Share Posted July 22, 2010 It can even be cool:$sInputString = "A1B2C3" & @CRLF & "abcd" For $iChar In StringToASCIIArray($sInputString) Switch $iChar Case 13 MsgBox(64, "Chr(13)", "'Enter' char", 2) Case 48 To 57 MsgBox(64, "Int", "Number = " & Chr($iChar), 2) Case 65 To 90 MsgBox(64, "Uppercase character", "Character = " & Chr($iChar), 2) Case 97 To 122 MsgBox(64, "Lowercase character", "Character = " & Chr($iChar), 2) EndSwitch Next ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
jaberwacky Posted July 22, 2010 Share Posted July 22, 2010 (edited) If you're sring contains too many characters to fit neatly into an array then you could do this... A string can contain around 2 billion characters and an array can contain around 16 million elements. Of course you'll wanna spend some time making it more robust and customized to your needs. Global Const $string = "HELLO AUTOIT!" Global Const $length = StringLen($string) Global $char For $i = 1 To $length $char = StringMid($string, $i, 1) ConsoleWrite($char & @TAB & $i & @LF) Next Edited July 22, 2010 by jaberwocky6669 0x90 1 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? 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