View previous topic :: View next topic |
Author |
Message |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1751 Location: Space and Time
|
Posted: Wed Feb 04, 2004 1:14 pm Post subject: Parse DSU |
|
|
Yes, here is another unit.
This unit is like the PARSE command except it is for an unknown ammount of parse items.
Useage: %t = @parse([string],[Field Sep (Optional)])
Returns a string with each item on a seperate line.
DOWNLOAD _________________ Chris
Http://theblindhouse.com |
|
Back to top |
|
|
Serge Professional Member
Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Wed Feb 04, 2004 1:50 pm Post subject: |
|
|
this is going to be very handy...thanks chris
serge _________________
|
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Wed Feb 04, 2004 3:21 pm Post subject: |
|
|
Sounds interesting! Is it a true record parser like VDS PARSE? I mean, does it acknowledge quoted fields so
you can have field contents holding the field sep character?
"field1";"field2:strg2";"field3;strg3"
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
Back to top |
|
|
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1751 Location: Space and Time
|
Posted: Wed Feb 04, 2004 3:40 pm Post subject: |
|
|
No. It do not see the "s. It will still see the fieldsep within the "s and parse that as well. I'll look into that and see if I can get that to work. _________________ Chris
Http://theblindhouse.com |
|
Back to top |
|
|
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1751 Location: Space and Time
|
Posted: Thu Feb 05, 2004 12:37 pm Post subject: |
|
|
Hey Dread. I can make a true record with this. I'll work on it and post it ASAP. _________________ Chris
Http://theblindhouse.com |
|
Back to top |
|
|
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1751 Location: Space and Time
|
Posted: Thu Feb 05, 2004 1:10 pm Post subject: |
|
|
Ok, @parse() has been updated. It is now a true parser.
Code: |
%s = @chr(34)test;test@chr(34);test;test
%t = @parse(%s,
# This will return
#
# test;test
# test
# test
|
DOWNLOAD _________________ Chris
Http://theblindhouse.com |
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Thu Feb 05, 2004 4:02 pm Post subject: |
|
|
Great. Took it for a quick spin...
Did you consider that when parsing flat-file db-records, there will often be empty fields?
"field1";"";"field3"
or
;;"field1";;"field3"
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
Back to top |
|
|
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1751 Location: Space and Time
|
Posted: Thu Feb 05, 2004 4:07 pm Post subject: |
|
|
Man, pickey pickey. I did not. Did you gice that a try? I will not have time to look at it right now. Give it a try and post what you did and what it returns.
Thanks _________________ Chris
Http://theblindhouse.com |
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Thu Feb 05, 2004 7:59 pm Post subject: |
|
|
Yeah. I did try it - actually that's why I asked coz when parsing records you're gonna run into this type of
record sooner or later.
I do lots of flat-file db parsing in VDS so I'm acquainted with it. I think I may have a similar routine lying
around somewhere. I'll see if I can dig it up.
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Thu Feb 05, 2004 8:12 pm Post subject: |
|
|
Right. I found it...
Code: |
%%fieldsep = ";"
option fieldsep,%%fieldsep
%%string = @CHR(34)@CHR(34);@CHR(34)1@CHR(34);2;@CHR(34)3;A@CHR(34);@CHR(34)4@CHR(34);;
list create,1
repeat
parse "%%item",%%string
%%itemlen = @len(%%item)
list add,1,%%item
REM Remove quote if string starts with it
if @equal(@substr(%%string,1),@CHR(34))
%%string = @strdel(%%string,1,)
end
REM Remove already extracted field content
%%string = @strdel(%%string,1,%%itemlen)
REM Remove quote if current field was enclosed
if @equal(@substr(%%string,1),@CHR(34))
%%string = @strdel(%%string,1,)
end
REM Now remove fieldsep
if @equal(@substr(%%string,1),%%fieldsep)
%%string = @strdel(%%string,1,)
end
until @null(%%string)
info @text(1)
list close,1
|
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
Back to top |
|
|
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1751 Location: Space and Time
|
Posted: Thu Feb 05, 2004 8:16 pm Post subject: |
|
|
Nice. I'll update the DSU adding your code. Thanks. _________________ Chris
Http://theblindhouse.com |
|
Back to top |
|
|
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1751 Location: Space and Time
|
Posted: Thu Feb 05, 2004 8:27 pm Post subject: |
|
|
It has been updated. Thanks again. _________________ Chris
Http://theblindhouse.com |
|
Back to top |
|
|
Dr. Dread Professional Member
Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
|
Back to top |
|
|
|