jamesstp20 Posted April 22, 2011 Posted April 22, 2011 (edited) Hello, I would like to do something like this but I don't know how: $String = "AABABD" For Each $letter in $String : If $letter =A then.. elseif $letter = B then .... And I would like to do that with each letter of my string. Thanks Edited April 22, 2011 by jamesstp20
Moderators Melba23 Posted April 22, 2011 Moderators Posted April 22, 2011 jamesstp20,Use StringSplit to get the characters into an array and then loop through them, or use StringMid to extract each character in turn - then use Switch: $sString = "AABABD" ConsoleWrite("Using StringSplit" & @CRLF) $aString = StringSplit($sString, "") For $i = 1 To $aString[0] Switch $aString[$i] Case "A" ConsoleWrite("Character " & $i & " is an A" & @CRLF) Case "B" ConsoleWrite("Character " & $i & " is an B" & @CRLF) Case Else ConsoleWrite("Character " & $i & " is neither A nor B" & @CRLF) EndSwitch Next ConsoleWrite(@CRLF & "Using StringMid" & @CRLF) For $i = 1 To StringLen($sString) Switch StringMid($sString, $i, 1) Case "A" ConsoleWrite("Character " & $i & " is an A" & @CRLF) Case "B" ConsoleWrite("Character " & $i & " is an B" & @CRLF) Case Else ConsoleWrite("Character " & $i & " is neither A nor B" & @CRLF) EndSwitch NextAll clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
UEZ Posted April 22, 2011 Posted April 22, 2011 Try this: $String = "AABABD" $aString = StringSplit($String, "", 2) For $Letter In $aString If $Letter = "B" Then MsgBox(0, "Information", "Letter B found") Next Probably M23 was faster... Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
kaotkbliss Posted April 22, 2011 Posted April 22, 2011 I would do something like this maybe? $string = "AABABD" $len = StringLen($string) For $i = 1 To $len $left = StringLeft($string, 1) Select Case $left = "A" MsgBox(0, "A", "The character is A") Case $left = "B" MsgBox(0, "B", "The Character is B") Case $left = "D" MsgBox(0, "D", "The character is D") EndSelect $string = StringTrimLeft($string, 1) Next 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
Moderators Melba23 Posted April 22, 2011 Moderators Posted April 22, 2011 UEZ,Probably M23 was faster...You need to speed up yout typing! Frohe Ostern! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
GEOSoft Posted April 22, 2011 Posted April 22, 2011 And you need to speed up youtyour spell checking! George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
jamesstp20 Posted April 22, 2011 Author Posted April 22, 2011 Thanks to both of you !!! All those 3 methods are working fine I will take the one of UEZ because it's cleaner ^^ Thanks !
UEZ Posted April 22, 2011 Posted April 22, 2011 UEZ,You need to speed up yout typing! Frohe Ostern! M23I'm 39 and speeding up typing will probably not work. Dir auch Frohe Ostern! Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
jamesstp20 Posted April 22, 2011 Author Posted April 22, 2011 Ok well now it's a little more complicated... I want to do the same thing if $Letter = "s" then If the next letter is "A" than.. Else If the next letter is B..... Thanks..
jamesstp20 Posted April 22, 2011 Author Posted April 22, 2011 Fine I found $sString = "AABABDSB" ConsoleWrite("Using StringSplit" & @CRLF) $aString = StringSplit($sString, "") For $i = 1 To $aString[0] If $aString[$i] = "S" Then MsgBox(0,"", $aString[$i +1]) Next
Flok3r Posted August 23, 2011 Posted August 23, 2011 I know this post is old and my comment redundant, since its nothing new, but perhaps it could help some unexperienced autoitters ;D expandcollapse popup#include <Constants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $str[20], $trimmed = 0, $alltrimmed = 0, $stout = "", $rx_sub = 0, $tx_sub = 0 $Form1 = GUICreate("Consumption", 120, 85, 5, 5, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) $Label1 = GUICtrlCreateLabel("Down Mb", 3, 5, 55, 20) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Input1 = GUICtrlCreateInput("0", 65, 3, 55, 20, BitOR($ES_AUTOHSCROLL,$ES_READONLY)) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("Up Mb", 3, 25, 55, 20) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Input2 = GUICtrlCreateInput("0", 65, 23, 55, 20, BitOR($ES_AUTOHSCROLL,$ES_READONLY)) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Label3 = GUICtrlCreateLabel("Used Mb", 3, 45, 55, 20) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Input3 = GUICtrlCreateInput("0", 65, 43, 55, 20, BitOR($ES_AUTOHSCROLL,$ES_READONLY)) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $reset = GUICtrlCreateButton("Reset", 3, 63, 114, 20) GUISetState(@SW_SHOW) adlibregister("GetInfo", 1000) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $reset Global $rx_sub = $rx_sub + $rx Global $tx_sub = $tx_sub + $tx GUICtrlSetData($reset,"Resetting..") GetInfo() GUICtrlSetData($reset,"Reset") EndSwitch WEnd Func GetInfo() $cmd = Run(@comspec & " /c netstat -e", @SystemDir, @SW_HIDE, $STDIN_CHILD & $STDOUT_CHILD) Sleep(500) $line = StdoutRead($cmd) ;getting from STDOUT only number of received bytes and update control whith this info: $str = StringSplit($line,@CR) For $i = 1 to $str[0]-1 Step 2 If $str[$i] <> "" And $i = 5 Then $strn = StringSplit($str[$i],"") $string = StringReplace($str[$i],"Bytes","") While 1 $test = StringMid($string, 1, 1) If Not StringIsDigit($test) Then $string = StringTrimLeft($string,1) ElseIf StringIsDigit($test) Or @error Then ExitLoop EndIf WEnd While 1 $test = StringMid($string, StringLen($string) -1, 1) If Not StringIsDigit($test) Then $String = StringTrimRight($string,1) ElseIf StringIsDigit($test) Or @error Then ExitLoop EndIf WEnd $strings = StringSplit($string, " ") Global $rx = $strings[1] Global $tx = $strings[$strings[0]] $all = $rx + $tx GUICtrlSetData($Input1, Round(($rx - $rx_sub)/ (1024 * 1024), 2)) GUICtrlSetData($Input2, Round(($tx - $tx_sub)/ (1024 * 1024), 2)) GUICtrlSetData($Input3, Round(($all - $tx_sub - $rx_sub)/ (1024 * 1024), 2)) $stout = "" $trimmed = 0 $alltrimmed = 0 EndIf Next EndFunc
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