#137738 - 2005-04-12 02:16 PM
Split Array
|
Testprs
Fresh Scripter
Registered: 2004-09-02
Posts: 20
Loc: Netherlands, Delft
|
Hi,
I'm trying to create a script that reads from a csv file. I then want the text from each column to be split in two. this is the code I've created so far (maybe this explains a bit more)
Code:
IF Open(3,"C:\helpdesk\kix\la.csv") = 0 $x = ReadLine(3) WHILE @ERROR = 0 $Value = Split($x,",") For Each $Element In $Value ? $Element Next $x = ReadLine(3) LOOP Close (3) ELSE BEEP ? "Cannot open file, error code: [" + @ERROR + "] + " " "@SERROR"" ENDIF
The la.csv file exists of two columns with value's that belong together. How can I split these values? example: $ElementPart1 $ElementPart2
regards,
Jeroen
|
|
Top
|
|
|
|
#137740 - 2005-04-12 02:46 PM
Re: Split Array
|
Testprs
Fresh Scripter
Registered: 2004-09-02
Posts: 20
Loc: Netherlands, Delft
|
csv file: computer1,user1 computer2,user2 computer3,user3
it's for usage in another script. this other script checks pc's for local admin rights and removes them unless they are in a list. This list is currently a big script, but by providing a csv file there will be a better view on who has these rights.
regards,
jeroen
|
|
Top
|
|
|
|
#137741 - 2005-04-12 02:49 PM
Re: Split Array
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Think you got all code there, and working:
Code:
break on
IF Open(3,".\t.csv") = 0 $x = ReadLine(3) WHILE @ERROR = 0 $Value = Split($x,",") If UBound($Value) > 0 $computer = $Value[0] $user = $Value[1] ?"computer=" + $computer + " user=" + $user Endif $x = ReadLine(3) LOOP $= Close (3) ELSE BEEP ? "Cannot open file, error code: [" + @ERROR + "] + " " "@SERROR"" ENDIF
-Shawn
|
|
Top
|
|
|
|
#137742 - 2005-04-12 02:52 PM
Re: Split Array
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
you can also use ReadFile() to import the file into an array
then do a for each, split each element, ...
|
|
Top
|
|
|
|
#137743 - 2005-04-12 03:04 PM
Re: Split Array
|
Testprs
Fresh Scripter
Registered: 2004-09-02
Posts: 20
Loc: Netherlands, Delft
|
Thanks... works like a charm!  could you please give me some more info on what the code exactly does? what does UBound do? I looked it up in the manual, but couldn't really figure it out (total newby! ) what do the [number] value's mean in $Value[0] and $Value[1]?
thanks for the help... regards,
jeroen
|
|
Top
|
|
|
|
#137744 - 2005-04-12 03:19 PM
Re: Split Array
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
ubound = number of elements in an array [number] = the item in an array (starting at 0)
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 837 anonymous users online.
|
|
|