forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Parsing problems
Goto page Previous  1, 2, 3, 4, 5
 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sun Dec 15, 2002 8:59 am    Post subject: Reply with quote

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... Wink

Cheers, Mac Smile

_________________
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
View user's profile Send private message Send e-mail
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Sun Dec 15, 2002 9:04 am    Post subject: Reply with quote

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
View user's profile Send private message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sun Dec 15, 2002 9:06 am    Post subject: Reply with quote

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. Wink

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 Smile

_________________
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
View user's profile Send private message Send e-mail
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Sun Dec 15, 2002 9:32 pm    Post subject: Reply with quote

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
View user's profile Send private message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Sun Dec 15, 2002 9:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
Tommy
Admin Team


Joined: 16 Nov 2002
Posts: 746
Location: The Netherlands

PostPosted: Sun Dec 15, 2002 10:00 pm    Post subject: Reply with quote

Maybe kind of off-topic Confused, 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
View user's profile Send private message Send e-mail Visit poster's website
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Sun Dec 15, 2002 10:05 pm    Post subject: Reply with quote

Nice code. Very Happy
_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sun Dec 15, 2002 11:46 pm    Post subject: Reply with quote

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... Confused

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... Confused

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... Wink

Cheers, Mac Smile

_________________
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
View user's profile Send private message Send e-mail
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Mon Dec 16, 2002 12:34 am    Post subject: Reply with quote

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
View user's profile Send private message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Mon Dec 16, 2002 1:06 am    Post subject: Reply with quote

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? Confused

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... Razz Laughing

Cheers, Mac Smile

_________________
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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Bug Reports All times are GMT
Goto page Previous  1, 2, 3, 4, 5
Page 5 of 5

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group