Jump to content

How do I use StringSplit


Recommended Posts

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

Link to comment
Share on other sites

#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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...