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 with double quotes

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Mon Jul 05, 2004 8:12 am    Post subject: Parsing with double quotes Reply with quote

I think I just found a bug (or handy trick) with the parse command. If you put double quotes around the current fieldseperator, it won't be recognized by the parse command:

Code:
option fieldsep,|
parse "%1;%2;%3;%4;%5",Hello|Hi|@chr(34)Howdy|test@chr(34)|Hey|Hoho

info %1@cr()%2@cr()%3@cr()%4@cr()%5


Please note that it will only work with "real" quotes, not the one which you can use in VDS to, for example, show an E-mail adres in an info command (info E-mail me at "bla@here.com")... Smile

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Mon Jul 05, 2004 8:47 am    Post subject: Reply with quote

It would be a bug if it didn't work that way... otherwise you would have problems when using PARSE
for database files where your field sep may occur inside field contents.

Greetz
Dr. Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Mon Jul 05, 2004 8:51 am    Post subject: Reply with quote

I don't really know about that. Because if you have database file which is using single quotes to keep the field contents together, it still doesn't work properly if one of these field contents has a double quote in it. When using database files, I think it's best to make a parsing routine yourself insteed of using the parse command... Smile
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Garrett
Moderator Team


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

PostPosted: Mon Jul 05, 2004 3:39 pm    Post subject: Reply with quote

Recently, I started building a little app to help me manage a CSV database
for a small web site that I'm taking over. I decided to go with a CSV that
is as close to the ?known? standards as possible, which means that each
entry is bound by a quote mark, and each entry is seperated by a comma.

Quote:
"1st entry","2nd entry","","4th entry"


Unfortunately, the PARSE command is just not quite up to the job of trying
parse out such a thing, because the data itself may have comma marks or
quote marks.

I ended up using @pos() to sort out everything, which works out great in
end. I now have a CSV routine that can basically be used in just about
any possible CSV situation. Unless! one of the data entries just happens
contain a quote comma quote in the darn thing! Sad

If there's any interest, I might try putting together a dsu to make CSV
easier for anyone who might need it. Unless I just reinvented the
wheel and someone already put some CSV code on the main site or
in the forum here.... Damn! I should have searched the site and forum
first before I did all this!! Laughing

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Mon Jul 05, 2004 8:39 pm    Post subject: Reply with quote

Hmm. I should have thought the parse command would cope with comma separated data okay. This works as I would expect:
Code:

  title test
  list create,1
  list loadtext,1
""Smith","23, Main Road","Anytown"
  option fieldsep,","
  %%data = @next(1)
  info Data: %%data
  parse "%%name;%%address;%%town",%%data
  info Name: %%name@cr()Address: %%address@cr()Town: %%town
  list close,1

_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Tue Jul 06, 2004 5:34 am    Post subject: Reply with quote

I've been using PARSE for flatfile databases for a long time. Field sep's inside fields haven't
been any problem as long as the fields are quoted (standard double quotes). Double quotes
inside fields may, however, be problematic; I don't allow them in there, replace by single
quotes.

Greetz
Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
Garrett
Moderator Team


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

PostPosted: Tue Jul 06, 2004 3:56 pm    Post subject: Reply with quote

Unfortunately for me, the data is based on data that I can't change to
fit my needs. If it were so, I would have used @tab() for the seperater
instead. That, and the fact that the csv file is going to be available for
other people to use, so I have to keep it all intact and in proper format.

Honestly though, I don't have a problem using the @pos() loop. In fact,
I kind of feel safer doing it this way than relying on the PARSE command.

Also, if you think about it, using PARSE means that you have to hard code
how many fields will be present, but using @pos() and a list, you can code
a csv program that can be flexible and dynamic.

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Tue Jul 06, 2004 6:23 pm    Post subject: Reply with quote

OK. I only brought it up because this has been posted under Bug Reports. The Parse command was really intended to provide a way of getting the information from VDS functions that can return multiple values in one call, like @verinfo, @file etc. It's handy that it can be used for other things, but I don't think that its failure to work with CSV files counts as a bug.
_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
Garrett
Moderator Team


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

PostPosted: Tue Jul 06, 2004 7:26 pm    Post subject: Reply with quote

I agree.
_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Wed Jul 07, 2004 5:44 am    Post subject: Reply with quote

Moved to General Help. Smile
_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
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