Jump to content

Trim each array element differently then the next?


Recommended Posts

I can't figure out how to trim elements of an array at different places. _ArrayTrim obvoiusly can't help. I've tried using strings but my text needs to stay on seperate lines.(?)

I'm reading text files which look like:

command-description

command2-destription2

command3-description3

etc

I'm trying to seperate the commands/descriptions for placement into a listview ctrl.

Haven't been coding for a while, so I'm a bit rusty... :)

Func Go()
    $test = ""
    $test2 = ""
    $devname = ""
    GUICtrlDelete($makelist)
    _GUICtrlListView_DeleteAllItems ($test)
    $devresult = ""
    Dim $devresult
    Dim $file
    $devname = GUICtrlRead($data) & '.txt'          ;get the file name from drop down box and add the file extension
    _FileReadToArray('Devices\' & $devname,$file)       ;create an array with the file contents
    _ArrayDelete($file, 0)  
        For $i = 0 To UBound($file) - 1
            $dash = StringInStr($file[$i],"-")              ;find out where the dash is in the text
            $devresult2 = _ArrayTrim($file,$dash,0)         ;get the second part of the text
            $devresult = _ArrayTrim($file,StringLen($file[$i])-$dash+1) ;get the first part of the text
        Next
    $makelist = GUICtrlCreateListView("Command              ", 10, 120, 400, 100)
    _GUICtrlListView_InsertColumn($makelist, 1, "Description", 250)
    ; Loop through each element of the array for list placement
    For $i = 0 To UBound($devresult) - 1
        $test = GUICtrlCreateListViewItem($devresult[$i], $makelist)
        $test2 = _GUICtrlListView_SetItemText($makelist, $i, $devresult2[$i], 1)
    Next
EndFunc   ;==>Go

Thanks!

Edited by Teldin
Link to comment
Share on other sites

Why are you using _ArrayTrim()? Use StringSplit().

$line = "command-description"

$temp = $StringSplit($line, "-")

ConsoleWrite($temp[1] & @CRLF) ;command

ConsoleWrite($temp[2] & @CRLF) ;description

EDIT: Mis-typed StringSplit() param

Edited by weaponx
Link to comment
Share on other sites

Maybe I' am really really rusty but with your example the array looks like:

command

descriptioncommand2

description2command3

description3

The best array I could get with stringstrip is:

command

description

command2

description2

command3

description3

From there I gave up trying to pull out the even and odd elements

I'm trying to get the array to look like:

---------------------

col0 | col1

----------------------

command | description

----------------------

command2 | description2

----------------------

etc...

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