Ctwizzy Posted November 14, 2006 Posted November 14, 2006 Im trying to put the clipboard contents into an array I was originally copying the clipboard to a file and then doing filetoarray, but I now want to skip this step and go from cliptoarray. This is what im tring to do #include <file.au3> Dim $aRecords = ClipGet() Dim $pinfile = "newpins.txt" $file = FileOpen($pinfile, 1) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf For $x = 1 to $aRecords[0] If StringInStr($aRecords[$x], "mystring") Then $val = $aRecords[$x] FileWrite($file, $val) EndIf Next FileClose($file) This wont work tho as $aRecords is no longer an array, so how can I make it an array instead of a really long string?
Moderators SmOke_N Posted November 14, 2006 Moderators Posted November 14, 2006 You have to make it an array first... Dim $aRecords = StringSplit(StringStripCR(ClipGet()), @LF) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
MadMaxx Posted June 10, 2010 Posted June 10, 2010 (edited) Hi I am trying to do a similar thing but I have multi lines and multi columns on the clipboard. Seperation of Lines = CRLF Seperation of Columns = Tab (had to use spaces to clarify here) Example: 12345{Tab}JOB ONE{Tab}6{Tab}Customer Services 12346{Tab}JOB TWO{Tab}3{Tab}Service 12347{Tab}JOB THREE{Tab}1{Tab}Service Any assistance would be grately appreciated. Rgds M Edited June 10, 2010 by MadMaxx
Malkey Posted June 10, 2010 Posted June 10, 2010 Try these slightly varying methods. expandcollapse popup#include <array.au3> ; For test purposes only (_ArrayDisplay) ;#cs ; ====== Comment out if text already on clip board ======== Local $sClip = "Code" & @TAB & "Title" & @TAB & "Frequency" & @TAB & "Dept" & @CRLF & _ "12345" & @TAB & "JOB ONE" & @TAB & "6" & @TAB & "Customer Services" & @CRLF & _ "12346" & @TAB & "JOB TWO" & @TAB & "3" & @TAB & "Service" & @CRLF & _ "12347" & @TAB & "JOB THREE" & @TAB & "1" & @TAB & "Service" ClipPut($sClip) ;#ce ; ========================================================= Local $sStr = ClipGet() Local $a1DArray, $NumOfLines, $cols, $c = 0 $a1DArray = StringSplit(StringStripCR($sStr), @TAB & @LF, 2) ; or ;$a1DArray = StringRegExp($sStr, "(.+?)(?:\s{2,}|\t|$)", 3) ; Will also split on 2 or more spaces StringReplace($sStr, @LF, @LF) $NumOfLines = @extended + 1 ; Plus one to include last line (which has as no @LF) $cols = UBound($a1DArray) / ($NumOfLines) Local $aRet2D[$NumOfLines][$cols] For $i = 0 To $NumOfLines - 1 For $j = 0 To $cols - 1 $aRet2D[$i][$j] = $a1DArray[$c] $c += 1 Next Next ConsoleWrite(ClipGet() & @CRLF) _ArrayDisplay($aRet2D, "New Array") ; or $arr = _StringTo2DArray(ClipGet()) _ArrayDisplay($arr, "From _FileReadTo2DArray") Func _StringTo2DArray($sStr) Local $c = 0 $sStr = StringStripWS($sStr, 2) $aTmp = StringSplit($sStr, @LF) ;Local $aLines = StringSplit(StringStripCR($sFileContent), @TAB & @LF) Local $aLines = StringRegExp($sStr, "(.+?)(?:\s{2,}|\t|$)", 3) Local $iCol = (UBound($aLines)) / $aTmp[0] Local $arr[$aTmp[0]][$iCol] For $i = 0 To UBound($aLines) - $iCol Step $iCol For $x = 0 To UBound($arr, 2) - 1 $arr[($i / $iCol)][$x] = $aLines[$c] $c += 1 Next Next Return $arr EndFunc ;==>_StringTo2DArray
MadMaxx Posted June 10, 2010 Posted June 10, 2010 Thanks Malkey. I used the Function one at the end after trying all of them. Forgot to mention that I am a total Newbee to this kinda thing. I am a recent convert from AutoHotKey which I was just getting to grips with when my boss decided we should be using AutoIt instead. Thanks again for the help. M
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