Jump to content

Looping through a string?


Recommended Posts

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 :blink: - Btw, what is "help file" ? I use the online docs as reference (coding in a non-SCiTe editor).

Edited by Xibalba
Link to comment
Share on other sites

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.

:blink:

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

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 :blink:

Edited by ALTIN
Link to comment
Share on other sites

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

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 by jaberwocky6669
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...