redpicker Posted May 19, 2009 Posted May 19, 2009 I know this is simple, but I can't figure it out. I read data from a file that is formatted as Data1a{tab}Data2a{tab}Data3a{CRLF} Data1b{tab}Data2b{tab}Data3b{CRLF} Data1c{tab}Data2c{tab}Data3c{CRLF} Data1d{tab}Data2d{tab}Data3d{CRLF} Data1e{tab}Data2e{tab}Data3e{CRLF} I copy this data to the clipboard just fine I want to put it into a 2D array Dim $avArray [5][2] $avArray = StringSplit(ClipGet(), Chr(9), @CRLF) What I am wanting to say is, split the string in the cllipboard into an array with tabs separating columns and CRLF separating rows, but it doesn't work. How do I split the string the way I want it? Thanks
Authenticity Posted May 19, 2009 Posted May 19, 2009 #include <Array.au3> Dim $sStr, $sPatt Dim $aLines, $aColumns, $aTotal[1][3] = [[0]] $sStr = 'Data1a' & @TAB & 'Data2a' & @TAB & 'Data3a' & @CRLF & _ 'Data1b' & @TAB & 'Data2b' & @TAB & 'Data3b' & @CRLF & _ 'Data1c' & @TAB & 'Data2c' & @TAB & 'Data3c' & @CRLF & _ 'Data1d' & @TAB & 'Data2d' & @TAB & 'Data3d' & @CRLF & _ 'Data1e' & @TAB & 'Data2e' & @TAB & 'Data3e' & @CRLF $aLines = StringSplit(StringStripWS($sStr, 3), @CRLF, 1) For $i = 1 To $aLines[0] $aColumns = StringSplit($aLines[$i], @TAB) $aTotal[0][0] += 1 ReDim $aTotal[$aTotal[0][0]+1][3] For $j = 1 To $aColumns[0] $aTotal[$aTotal[0][0]][$j-1] = $aColumns[$j] Next Next _ArrayDisplay($aTotal) StringSplit() return a one-dimensional array type.
redpicker Posted May 20, 2009 Author Posted May 20, 2009 <Snip>StringSplit() return a one-dimensional array type.Thanks. I was afraid that StringSplit() would only do a 1D array, but I was hoping it would do a 2D. In any case, your code does the trick. Thanks a lot.rp
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