1 / 10

Arrays and String Manipulation

Arrays and String Manipulation. Week 6. Arrays. $ arr [3] ; Make room for three elements ;Assign some data. Array starts from 0 position $ arr [0]="Element 1" $ arr [1]="Element 2" $ arr [2]="Element 3“ Msgbox (0,"", $ arr [2]). Another way to Declare Arrays.

Download Presentation

Arrays and String Manipulation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Arrays and String Manipulation Week 6

  2. Arrays $arr[3] ; Make room for three elements ;Assign some data. Array starts from 0 position $arr[0]="Element 1" $arr[1]="Element 2" $arr[2]="Element 3“ Msgbox(0,"", $arr[2])

  3. Another way to Declare Arrays $arr[3] = ["element 1", "element 2", "element 3"] Msgbox(0,"", $arr[2])

  4. String Manipulation • Very practical, but a bit boring • Lots of String Manipulation Functions • StringInStr, StringLen, StringLower, StringMid, StringRight, StringTrimLeft, StringTrimRight, StringUpper, StringCompare, StringReplace, StringSplit

  5. Skeleton Code – Excel Control #include "U:\MURT 102\install\Include\Excel.au3" ; If you have the full installation of AutoIt, you don't need to give the pathname, but can just provide Excela.u3 ;All future code should include this template http://cl1p.net/123456789 HotKeySet("{ESC}", "Quit") HotKeySet("{F1}", "Start") While 1 Sleep(100) Wend Func Start() $oExcel = RunExcel() for $r = 1 to 10 $myString = _ExcelReadCell($oExcel, $r,1) ;Value read from cell ;Your Code Goes Here _ExcelWriteCell($oExcel, $myString, $r,$c) next EndFunc ;==>Start Func Quit() Exit EndFunc ;==>Quit FuncRunExcel() Local $arr[10] = ["element 1", "element 2", "element 3", "element 4", "element 5", "element 6", "element 7", "element 8", "element 9", "10th element"] $oExcel = _ExcelBookNew() $c = 1 for $r = 1 to 10 _ExcelWriteCell($oExcel, $arr[$r-1], $r,$c) next return $oExcel EndFunc

  6. Grab the Numbers on the Right • Grab the numbers of the right with StringRight • Check if the value is a number with StringIsDigit • Past the number into the adjacent column with _ExcelWriteCell($oExcel, $myString,$r,2) • Make this now work using StringTrimRight • Remove the n-number of characters with StringLen()

  7. String in Strings • Find the string “1” with StringInStr • If you find it, put in the column “I found it” • Replace with word “element” with “M&M” using StringReplace

  8. String Compare • Let’s modify our Google/Notepad program to look at any combination of LowerCase or UpperCase versions of “FireFox” or “notepad” using StringCompare • Skeleton Code on Next Page

  9. Skeleton Code ;All future code should include this template http://cl1p.net/123456789 HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "Start") HotKeySet("{F1}","CloseWindow") While 1 Sleep(100) Wend Func Start() $val = inputbox("","Type in your Program") If $val == "notepad" Then run("notepad.exe") WinWaitActive("[Class:Notepad]") Send("Hello") ElseIf $val == "firefox" Then run("C:\Program Files\Mozilla Firefox\firefox.exe") WinWaitActive("[Class:MozillaUIWindowClass]") ControlClick("[Class:MozillaUIWindowClass]","","[CLASS:MozillaWindowClass; INSTANCE:1]","left",1,384, 35) sleep(10) ControlSend("[CLASS:MozillaUIWindowClass]", "","[CLASS:MozillaWindowClass; INSTANCE:1]" , "http://www.google.com{ENTER}") WinWaitActive("Google") Else Traytip("Wrong Input", $val, 10) Start() EndIf EndFunc Func Quit() Exit EndFunc FuncCloseWindow() If WinActive("[Class:Notepad]") Then WinClose("[Class:Notepad]") ElseIfWinActive("[Class:MozillaUIWindowClass]") Then WinClose("[Class:MozillaUIWindowClass]") EndIf EndFunc

  10. Let’s Talk about Projects We’ve lost Fridays You have Spring Break You guys are already skilled

More Related