Page 1 of 1 1
Topic Options
#113779 - 2004-02-11 01:56 PM Using udfSqueeze to remove and split
Grutte Pier Offline
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
#113780 - 2004-02-11 02:12 PM Re: Using udfSqueeze to remove and split
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
I won't go fixing your code but have a suggestion to your question.

what about:
$stringWOquotes=join(split($stringWquotes,'"'),'')

and to make it array right away:
$arrayWOquotes=split(join(split($stringWquotes,'"'),''),',')

_________________________
!

download KiXnet

Top
#113781 - 2004-02-11 02:15 PM Re: Using udfSqueeze to remove and split
Howard Bullock Offline
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.

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#113782 - 2004-02-11 02:20 PM Re: Using udfSqueeze to remove and split
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja, I thought that too.
decided not to care just yet
_________________________
!

download KiXnet

Top
#113783 - 2004-02-11 02:25 PM Re: Using udfSqueeze to remove and split
Howard Bullock Offline
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...
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#113784 - 2004-02-11 03:27 PM Re: Using udfSqueeze to remove and split
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
There have been any number of CSV related threads.

Here is an old one which contains a UDF which handles all of Excels idiosyncracies:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB1&Number=35833

Top
#113785 - 2004-02-11 03:37 PM Re: Using udfSqueeze to remove and split
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands
Thanks Lonkero that fixed the problem.

Exelent answer

Top
#113786 - 2004-02-11 03:46 PM Re: Using udfSqueeze to remove and split
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I think I would Split() first on the 3 chars [","] to be safe in case there is a comma in the data. Then I would Join(Split()) on the comma to get rid of the odd quotes.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#113787 - 2004-02-11 03:55 PM Re: Using udfSqueeze to remove and split
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, there is problem with that.
"," assumes that if there is quotes around one block, also the preceding and following blocks do have them.
_________________________
!

download KiXnet

Top
#113788 - 2004-02-11 03:59 PM Re: Using udfSqueeze to remove and split
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't see it as a problem as all the fields in GP's example have quotes.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.098 seconds in which 0.063 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org