| View previous topic :: View next topic |
| Author |
Message |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Dec 15, 2002 8:59 am Post subject: |
|
|
Look close Garrett and I think you'll find that the leading
and trailing spaces are omitted, there's a "|" at one
end and a word at the other...
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sun Dec 15, 2002 9:04 am Post subject: |
|
|
There must be a difference between VDS 3 and VDS 4 on this, because I
lost no spaces at all with that code. It's actually very screwy.
Either way, it's not doing what I'd want it to do, which is to retain the
spaces, and not have to use funky code trying like I used to achieve it.
-Garrett |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Dec 15, 2002 9:06 am Post subject: |
|
|
We're talking about my example right?
Yours shows spaces because ya left spaces between the
vars on the INFO line. That's why I added ">" and "<"
around the vars and put 'em on separate lines.
Here's both of 'em, using the same string:
__________________________________________________________________________________________________________________________
| Code: |
TITLE Garrett's example
option fieldsep,[
%A = |" hello [|" world [|" ok |"
parse "%%part1;%%part2;%%part3", %A
info @len(%%part1)/@len(%%part2)/@len(%%part3)@cr()%%part1 - %%part2 - %%part3
TITLE Mac's example
option fieldsep,[
%A = |" hello [|" world [|" ok |"
parse "%%part1;%%part2;%%part3", %A
info @len(%%part1)/@len(%%part2)/@len(%%part3)@cr()@cr()>%%part1<@cr()@cr()>%%part2<@cr()@cr()>%%part3<
|
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sun Dec 15, 2002 9:32 pm Post subject: |
|
|
Ok, I made some code that works in both VDS 3 and 4. Try this:
| Code: | option fieldsep,[
%A = |" hello "|[|" world "|[|" ok "|
parse "%%part1;%%part2;%%part3",%A
info @len(%%part1)/@len(%%part2)/@len(%%part3)@cr()%%part1/%%part2/%%part3 |
or try this:
| Code: | option fieldsep,|
%A = [ hello ]|[ world ]|[ ok ]
parse "%%part1;%%part2;%%part3",%A
info @len(%%part1)/@len(%%part2)/@len(%%part3)@cr()%%part1/%%part2/%%part3 |
The spaces are retained doing this. The LEN of all should read 20.
-Garrett |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sun Dec 15, 2002 9:37 pm Post subject: |
|
|
Well now, if I use the @chr() for the comma and quote, it seems to
work fine.
| Code: | option fieldsep,@chr(44)
%A = @chr(34) hello @chr(34)@chr(44)@chr(34) world @chr(34)@chr(44)@chr(34) ok @chr(34)
parse "%%part1;%%part2;%%part3",%A
info @len(%%part1)/@len(%%part2)/@len(%%part3)@cr()%%part1/%%part2/%%part3 |
That works as I would want it to work when I deal with csv files.
-Garrett
PS. code may be wrapped on the line where the variable is set with
the data. |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sun Dec 15, 2002 10:00 pm Post subject: |
|
|
Maybe kind of off-topic , but anyway here's a really simple parser routine that does
retain spaces and does not require any @chr(34) to be present in the source string:
| Code: |
:parse
%p = @pos(%%sep,%%text)
if @greater(%p,0)
%%chunk = @substr(%%text,1,@pred(%p))
%%text = @strdel(%%text,1,%p)
else
%%chunk = %%text
%%text =
end
exit
|
Example of usage:
| Code: |
%%sep = |
%%text = " Tomorrow | Never|Dies "
gosub parse
info Chunk 1:@cr()@chr(34)%%chunk@chr(34)
gosub parse
info Chunk 2:@cr()@chr(34)%%chunk@chr(34)
gosub parse
info Chunk 3:@cr()@chr(34)%%chunk@chr(34)
exit
|
|
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Sun Dec 15, 2002 10:05 pm Post subject: |
|
|
Nice code.  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Dec 15, 2002 11:46 pm Post subject: |
|
|
| Garrett wrote: | Ok, I made some code that works in both VDS 3 and 4. Try this:
| Code: | option fieldsep,[
%A = |" hello "|[|" world "|[|" ok "|
parse "%%part1;%%part2;%%part3",%A
info @len(%%part1)/@len(%%part2)/@len(%%part3)@cr()%%part1/%%part2/%%part3 |
or try this:
| Code: | option fieldsep,|
%A = [ hello ]|[ world ]|[ ok ]
parse "%%part1;%%part2;%%part3",%A
info @len(%%part1)/@len(%%part2)/@len(%%part3)@cr()%%part1/%%part2/%%part3 |
The spaces are retained doing this. The LEN of all should read 20.
-Garrett |
Garrett, one of us is asleep at the wheel here...
There are no leading or trailing spaces in these two
examples. You have either a | or [ as the first and last
chars, which naturally preserves the spaces between them...
And your other example with the @chr(34) chars is the
method I've been pushing all along...
Tommy - Your last example captures the quotes from
a standard delimited file that has quotes around the fields,
so ya still gotta adjust for that.
I think one of the main issues here is the difference between
working from a loaded file and a variable. The quotes are
treated differently. PARSE could be made to work like ya want
with either one, but prolly not both. And there's always gonna
be some files that have the fields enclosed in quotes...
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Mon Dec 16, 2002 12:34 am Post subject: |
|
|
Mac, yes, exactly, it requires something to be the block end on two of the
examples, but, to put it all to rest, using the @chr() equivalents of the
comma and the quote mark works.
So it seems using nothing but spaces before and after are lost, using any
other character holds it, using quotes and comma's directly in the code
doesn't work, but using the @chr() code does work.
Personally, I would prefer that the spaces be retained regardless of quotes
or anything else. If I don't want them, then I can easily take care of them
once I have the csv file loaded.
-Garrett |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Mon Dec 16, 2002 1:06 am Post subject: |
|
|
OK - since data is prolly gonna have to be modified one
way or the other (because of the list/string difference),
everyone prefers to remove quotes from the fields (when
necessary) than add to them when needed?
I guess a PARSE that gives the option (as someone
mentioned earlier) would suit everyone best. LOL, it
doesn't make this one buggy though, just inadequate...
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|