Quafboy Posted November 21, 2009 Share Posted November 21, 2009 Firstly, kudos to the great AutoIT community. You have saved my butt at work numerous times by allowing me, a simple mind, to automate tasks that would be tedious and time consuming. Nod's specifically to valik and Smoke who have answered problems others have asked that pertain to problems I had numerous times. I am very grateful for you all. I swear I utilized search before posting this so if it has already been posted, by all means direct me accordingly. Now my problem. I can't think of a simple way to take clipboard contents and direct them into an array without using filereadtoarray which defeats the purpose of what I am trying to do. What I aim to accomplish is copying text out of notepad (multi-line) and put it into an array. Here is the code I have thus far: #include <Array.au3> Opt("WinWaitDelay",100) Opt("WinTitleMatchMode",4) Opt("WinDetectHiddenText",1) WinWait("Untitled - Notepad","") If Not WinActive("Untitled - Notepad","") Then WinActivate("Untitled - Notepad","") WinWaitActive("Untitled - Notepad","") Send("{CTRLDOWN}a{CTRLUP}") Send("{CTRLDOWN}c{CTRLUP}") $txt = ClipGet() StringSplit( $txt, @CRLF, 1) ;MsgBox(0,"test", $txt, 0) Local $ClipTxtArray[5] _ArrayAdd( $ClipTxtArray, StringSplit( $txt, @CRLF, 1)) _ArrayDisplay($ClipTxtArray) I would like to set the array size based on the number of @CRLF stringsplit processed instead of my finite number 5. What do I need to do to achieve this task? IF you don't want to give me the direct code could you please tell me what I need to do my homework on to arrive at a solution? Thank you all kindly. Link to comment Share on other sites More sharing options...
Authenticity Posted November 21, 2009 Share Posted November 21, 2009 You want to add to an existing array or to get an array from StringSplit? Read StringSplit function description and remarks. The return value is an array type, the first element contains the array's last index so all you need to do is:Local $avLines = StringSplit( $txt, @CRLF, 1) _ArrayDisplay($avLines)If you want to add to an existing array:Local $avArr[10] = [9, 1, 2, 3, 4, 5, 6, 7, 8, 9] Local $avLines = StringSplit( $txt, @CRLF, 3) ; 2 + 1 Disable first index, split on the entire delimiter. ReDim $avArr[$avArr[0]+UBound($avLines)] For $i = 0 To UBound($avLines)-1 $avArr[0] += 1 $avArr[$avArr[0]] = $avLines[$i] Next _ArrayDisplay($avArr) Link to comment Share on other sites More sharing options...
Quafboy Posted November 21, 2009 Author Share Posted November 21, 2009 You want to add to an existing array or to get an array from StringSplit? Read StringSplit function description and remarks. The return value is an array type, the first element contains the array's last index so all you need to do is: Local $avLines = StringSplit( $txt, @CRLF, 1) _ArrayDisplay($avLines) If you want to add to an existing array: Local $avArr[10] = [9, 1, 2, 3, 4, 5, 6, 7, 8, 9] Local $avLines = StringSplit( $txt, @CRLF, 3) ; 2 + 1 Disable first index, split on the entire delimiter. ReDim $avArr[$avArr[0]+UBound($avLines)] For $i = 0 To UBound($avLines)-1 $avArr[0] += 1 $avArr[$avArr[0]] = $avLines[$i] Next _ArrayDisplay($avArr) Thank's a million!!!!! That was exactly what I needed: Local $avLines = StringSplit( $txt, @CRLF, 1) _ArrayDisplay($avLines) I really appreciate it. IT was driving me crazy and no matter how many time's I read AutoIt help file I couldn't for the life of me figure this out. I'm still very much a beginner. Thank you thank you thank you. 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