#138861 - 2005-04-29 04:24 AM
Coma delimited files
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
Is there a way to read comma delimited files and put each segment in a variable. I know how to do it with a space delimited but with a coma delimited ???
|
Top
|
|
|
|
#138863 - 2005-04-29 06:04 PM
Re: Coma delimited files
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
Let's say the array is $ar and come from a text files and I want to split each segment in a different variable. I did try this and it does not work.
redirectoutput ('log.txt') $Ar = 1,2,3,5,7,11,17,13 $x = ASCAN($Ar, 13) ; will return '7'
? $x
sleep 5 $a = SPLIT ('$Ar', ',', 1) ;$b= SPLIT ("$array", ",", 1) ;$c= SPLIT ("$array", ",", 2) ;$d= SPLIT ("$array", ",", 3) ;$e= SPLIT ("$array", ",", 4) ;$f= SPLIT ("$array", ",", 5) ;$g= SPLIT ("$array", ",", 6) ;$h= SPLIT ("$array", ",", 7)
? $a ;? $b ;? $c ;? $d ;? $e ;? $f ;? $g ;? $h sleep 15
|
Top
|
|
|
|
#138864 - 2005-04-29 06:13 PM
Re: Coma delimited files
|
Les
KiX Master
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
First off, $AR is an array of values, not a comma delimited string. Code:
break on $CommaDelimString = '1,2,3,4,5,6,7,8,9,10' $CommaDelimArray = Split($CommaDelimString,',') For Each $Element In $CommaDelimArray $Element ? Next
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
Top
|
|
|
|
#138865 - 2005-04-29 08:12 PM
Re: Coma delimited files
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Just remember that some fields can contain commas that will cause problems using SPLIT.
Code:
ado.csv
Name,Position,ID "Blow, Joe",User,10001 "Doe, Mary",User,10002 "Doe, John",Admin,10003
In the above sample it may be beneficial to open the CSV using ADODB.
Code:
$adOpenStatic = 3 $adLockOptimistic = 3 $adCmdText = &1 $objConnection = CreateObject("ADODB.Connection") $objRecordSet = CreateObject("ADODB.Recordset") $sPathtoTextFile = "g:\" $objConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + $sPathtoTextFile + ";" + 'Extended Properties="text; HDR=YES; FMT=Delimited"')
$objRecordset.Open("SELECT * FROM ado.csv", $objConnection,$adOpenStatic,$adLockOptimistic,$adCmdText) Do $objRecordset.Fields("Name").Value ? $objRecordset.Fields("Position").Value ? $objRecordset.Fields("ID").Value ? $objRecordset.MoveNext Until $objRecordset.EOF $objRecordSet.Close $objConnection.Close
|
Top
|
|
|
|
#138867 - 2005-04-29 10:33 PM
Re: Coma delimited files
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
LES, they print on the screen but how to put them in variable.
|
Top
|
|
|
|
#138868 - 2005-04-29 11:06 PM
Re: Coma delimited files
|
Les
KiX Master
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
Code:
break on $CommaDelimString = '1,2,3,4,5,6,7,8,9,10' $CommaDelimArray = Split($CommaDelimString,',')
For $Index = 0 to UBound($CommaDelimArray) $CommaDelimArray[$Index] ? Next
$element0 = $CommaDelimArray[0] $element1 = $CommaDelimArray[1]
$element0 ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
Top
|
|
|
|
#138870 - 2005-04-30 02:19 AM
Re: Coma delimited files
|
normandbr
Fresh Scripter
Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
|
Thanks a lot LES, As you can see I am a rookie with kixtart.
|
Top
|
|
|
|
#138872 - 2005-04-30 05:41 AM
Re: Coma delimited files
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
|
Top
|
|
|
|
#138876 - 2005-05-01 03:33 AM
Re: Coma delimited files
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
Wow - Did I hear right (humble me), from Les
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 248 anonymous users online.
|
|
|