#113779 - 2004-02-11 01:56 PM
Using udfSqueeze to remove and split
|
Grutte Pier
Getting the hang of it
Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands
|
Hello,
I've got a txt file with line's like:
"Launch Success","10","10-2-2004 13:30:09","ORGANISATION::.BEHEERDER.ICT.PT3.PT.ORGANISATION","WORKSTATION NOT REGISTERED::WORKSTATION NOT REGISTERED","145.39.135.32","ORGANISATION::.APPICATION.MC.ORGANISATION","30490D3B-7DC5-41DA-BC59-C451B2DD3F54","","0","0","","","","","","524288"
Now I like to strip the quotes and split based on the comma's
I've tried to simplefy the task and make it work without the quotes and the working code is:
Code:
$file = "C:\nalmon.txt" $db = "C:\cmdb.mdb" ; -----------------------------------------------------------------------
Break on Dim $line Dim $field If Open(1,$file) = 0 While @ERROR = 0 $record = ReadLine(1) If NOT @error If $record $field = "" $field = Split($record,",") If Exist("$DB") = 0 ? "Database Not Found. Aborting..." Sleep 3 GoTo end EndIf $CNstring = "provider=microsoft.jet.oledb.4.0;data source=$DB;persist security info=false" $CMDtxt = "Select * from objectuse" $cn = CreateObject ("ADODB.Connection") $cmd = CreateObject ("ADODB.Command") $rs = CreateObject ("ADODB.RecordSet") $cn.connectionstring = $CNstring $cn.Open $cmd.activeconnection = $cn $rs.cursortype = 3 $rs.locktype = 3 $rs.activecommand = $cmd $cmd.commandtext = $CMDtxt $rs.Open ($cmd) $rs.addnew $rs.fields.item("EventType").value = $field[0] $rs.fields.item("EventTypeCode").value = $field[1] $rs.fields.item("DataandTime").value = $field[2] $rs.fields.item("UserDNTree").value = $field[3] ; $rs.fields.item("WorkstationDNTree").value = $field[4] $rs.fields.item("WorkstationAddress").value = $field[5] $rs.fields.item("ApplicationDNTree").value = $field[6] $rs.fields.item("ApplicationGUID").value = $field[7] $rs.fields.item("ApplicationVersionString").value = $field[8] $rs.fields.item("EventCodeMajor").value = $field[9] $rs.fields.item("EventCodeMinor").value = $field[10] $rs.fields.item("EventString1").value = $field[11] $rs.fields.item("EventString2").value = $field[12] $rs.fields.item("EventString3").value = $field[13] $rs.fields.item("EventString4").value = $field[14] $rs.fields.item("EventString5").value = $field[15] $rs.fields.item("ApplicationFlag").value = $field[16] $rs.update $rs.Close $objFSO="" EndIf EndIf Loop Else ?"Error opening $file" EndIf :END
Now I like to make this work with the quotes present in the format and remove and split them with udfSqueeze but no succes.
I've added the function code in top of the page and replaced Code:
$field = Split($record,",")
With Code:
$field = Split(udfSqueeze($record,'",',"true"))
But then you only remove the combination ", and so some lonly quotes and comma's stay behind.
Help....
Thanks,
GP
|
|
Top
|
|
|
|
#113781 - 2004-02-11 02:15 PM
Re: Using udfSqueeze to remove and split
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Lonk, there is a potential problem with the SPLIT logic using a comma. If there is an embedded comma within a text string wrapped by quotes, then the comma is data and not a delimiter that should be used to SPLIT the line.
|
|
Top
|
|
|
|
#113783 - 2004-02-11 02:25 PM
Re: Using udfSqueeze to remove and split
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
If I have time in the next couple days, I will write a udf that more properly handles delimited string manipulations...unless one already exists. I haven't checked yet...
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1046 anonymous users online.
|
|
|