View previous topic :: View next topic |
Author |
Message |
moke Contributor
Joined: 02 Jan 2002 Posts: 162
|
Posted: Wed Dec 11, 2002 8:28 pm Post subject: Parsing problems |
|
|
After a quick search on the board I couldn't find any data on the following problem:
When parsing a value VDS for some reason automatically removes the
the leading and trailing spaces. In another situation I might call this a
feature but not today. Has anyone had to deal with this? I need to
compare data for equal values and this is really screwing me up.
Am I missing something?
Code: |
%x = abc | def |123
parse "%a;%b;%c",%x
info <%a>-<%b>-<%c>
|
Any comments are welcome.
moke |
|
Back to top |
|
|
Skit3000 Admin Team
Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Wed Dec 11, 2002 8:37 pm Post subject: |
|
|
You can try to parse it yourself, and use it as a subroutine. But you'll have to use the same variables all the time...
Code: |
%x = " abc | def | 123 "
rem You can repeat the next two lines to parse more...
%a = @substr(%x,1,@pred(@pos(|,%x)))
%x = @strdel(%x,1,@pos(|,%x))
%b = @substr(%x,1,@pred(@pos(|,%x)))
%x = @strdel(%x,1,@pos(|,%x))
rem Use this one as the last one
%c = @substr(%x,1,@len(%x))
info <%a>-<%b>-<%c> |
|
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Dec 11, 2002 9:43 pm Post subject: |
|
|
Or ya could use @trim() on the other value you're
comparing...
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 |
|
|
moke Contributor
Joined: 02 Jan 2002 Posts: 162
|
Posted: Wed Dec 11, 2002 11:05 pm Post subject: |
|
|
Both good suggestions guys, thanks.
I assume this is actually a bug and not my cold infested, weary brain
playing tricks on me. Does someone want to move this post to the bug
reports? |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Dec 11, 2002 11:17 pm Post subject: |
|
|
I dunno moke. It's not a new thing, and I'm inclined
to agree with what ya said in your first post about it
being a feature...
Anyone else have an opinion? BUG or FEATURE?
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: Thu Dec 12, 2002 12:12 am Post subject: |
|
|
The data that's being parsed, is that data that you've built using
your program in the first place? If so, maybe try using " <data> "
(quote marks around the dat) when initially saving the data. The
spaces might be getting lost when sending the data to a list or
variable.
-Garrett |
|
Back to top |
|
|
cnodnarb Professional Member
Joined: 11 Sep 2002 Posts: 762 Location: Rockeledge, GA
|
Posted: Thu Dec 12, 2002 12:18 am Post subject: |
|
|
Bug. Should return the string parsed by delimiter, including spaces.
NodNarb |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Dec 12, 2002 12:18 am Post subject: |
|
|
Normal quotes won't work Garrett, but @chr(34) will.
They must be on each item to be parsed...
__________________________________________________________________________________________________________________________
Code: |
%%data = @chr(34) test1@chr(34)|@chr(34) test2 @chr(34)|@chr(34) test3 @chr(34)
PARSE "%a;%b;%c", %%data
INFO >%a<@cr()@cr()>%b<@cr()@cr()>%c<
|
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 |
|
|
moke Contributor
Joined: 02 Jan 2002 Posts: 162
|
Posted: Thu Dec 12, 2002 12:33 am Post subject: |
|
|
Garret,
The data is created with my app. The parse command is definately
changing the data on it's own. Obviously the two suggestions made will
work or you could use the opposite approach and edit it before writing
the data.
Technically speaking (in my book ), this is a bug. The parse command
is changing data on its own. The intent of the command is to parse data,
not manipulating strings ( as Mac has pointed out the @trim function
intentionally removes the spaces). It should return exactly what it reads
(unless of course there are nulls which VDS can't read). There is nothing
in the documentation stating that this is an intentional result of using the
parse command. |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Dec 12, 2002 12:42 am Post subject: |
|
|
Well, blanks are frequently ignored unless surrounded
by quotes, so I just don't see a divergence from the
norm here.
Try this code and add several blanks after 1234
with no quotes...
Code: |
%%data = 1234
INFO >%%data<
|
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 |
|
|
cnodnarb Professional Member
Joined: 11 Sep 2002 Posts: 762 Location: Rockeledge, GA
|
Posted: Thu Dec 12, 2002 1:13 am Post subject: |
|
|
I consider this to be another bug. ITT Tech is not a college with a whole lot of clout, but it is where I am learning to be a programmer. After learning about C++, Visual Basic, Java, Unix Scripting and a couple of other useful thingamajiggers; for what it's worth, I say this is a bug.
Brandon "NodNarb" Cunningham |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Dec 12, 2002 1:25 am Post subject: |
|
|
Well, standard ol' C/C++ doesn't give ya much choice.
It requires quotes on strings, or it expects a var...
strcpy(string, "Hello World");
VDS uses % to identify vars, and has untyped strings,
so comparing it to other languages is kinda like apples
and oranges....
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 |
|
|
moke Contributor
Joined: 02 Jan 2002 Posts: 162
|
Posted: Thu Dec 12, 2002 4:10 am Post subject: |
|
|
Fortunately this issue is easily worked around. And my thanks to Mac and Skit for jump starting my brain. Some how I have never had this problem in VDS before, but apparently others have. It seems there is a difference of opinion on the bug/no bug issue. I still say the intent of the command or function dictates it's performance and a deviation from that would be a bug. However, my imidiate problem is solved and you can call it a bug if you want or you can call it some tired sick old guy having a bad day take your pick, at least I got the job done.
Thanks,
moke |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Dec 12, 2002 4:21 am Post subject: |
|
|
Lol moke.
I think we should prolly get a few more opinions (including
Tommy's) before we declare it a bug. I'm not familiar with
a PARSE command in anything but VDS anyway...
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 |
|
|
PGWARE Web Host
Joined: 29 Dec 2001 Posts: 1563
|
Posted: Thu Dec 12, 2002 6:33 am Post subject: |
|
|
I see the PARSE command as a bug. It should definately preserve the spaces when loading a text file and especially when using quotation marks. Here is some code I threw together, showing the bugged vds PARSE and my own version of parse (it also may contain bugs so don't come blaiming me if you use it and problems arise):
Code: |
rem We create LIST 9 - Used to store the parsed words, if you change this
rem list number you must change it throughout the rest of the code too!
list create,9
rem Here we just set the entire text to parse, then we use a GOSUB to use the
rem NEW_PARSE, after the gosub it goes to the next line to complete the VDS
rem version of parse which does not preserve spaces between words!
%%thestring = " hello | world | how| is | life "
gosub NEW_PARSE
option fieldsep,|
parse "%%word1;%%word2;%%word3;%%word4;%%word5", %%thestring
rem Notice I use *** between parsed words, this is just to show that
rem VDS does not preserve spaces, the new parse does however. Also
rem note that to use the new parse you simply call the @item(9,LINE #)
rem to retrieve out the parsed words.
warn vds parse: ***%%word1***@cr()@cr()new parse: ***@item(9,0)***
warn vds parse: ***%%word2***@cr()@cr()new parse: ***@item(9,1)***
warn vds parse: ***%%word3***@cr()@cr()new parse: ***@item(9,2)***
warn vds parse: ***%%word4***@cr()@cr()new parse: ***@item(9,3)***
warn vds parse: ***%%word5***@cr()@cr()new parse: ***@item(9,4)***
rem We close the list box 9 and exit the script
list close,9
exit
:NEW_PARSE
rem Set the Fieldsep (must be 1 character) and the text to parse
rem Here I use the variable %%thestring which holds the text to parse.
%%OPTION_FIELDSEP = |
%%PARSEDSTR = %%thestring
rem PARSE ROUTINE START (no changes needed)
list clear,9
repeat
list add,9,@substr(%%PARSEDSTR,1,@pred(@pos(%%OPTION_FIELDSEP,%%PARSEDSTR)))
%%PARSEDSTR = @strdel(%%PARSEDSTR,1,@pos(%%OPTION_FIELDSEP,%%PARSEDSTR))
until @equal(@pos(%%OPTION_FIELDSEP,%%PARSEDSTR),0)
if @greater(@len(%%PARSEDSTR),0)
list add,9,%%PARSEDSTR
end
rem PARSE ROUTINE END (no changes needed)
exit
|
I used *** to show the spaces in between the parsed out words. Btw this uses a standard list to hold the parsed words, each word is placed on it's own line. Thus using @ITEM(9,LINE NUMBER) will get you the parsed word you want. |
|
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
|
|