| View previous topic :: View next topic |
| Author |
Message |
kc7aad Contributor

Joined: 09 Oct 2005 Posts: 53 Location: Spokane Washington
|
Posted: Sun Nov 25, 2007 8:21 am Post subject: I just can't grasp PARSE!! |
|
|
So I have used it with some code help from others before, but i'm trying to understand it! I just can't get it for some reason, and what ever I try, doesn't seem to work!!!!!!!
So.. I understand having to load files, and searching for things in a string.. Got that!
I use
PARSE "%1,%2,%3,%4",%5
BUT WHAT DO THEY MEAN?? I think %5 is the piece of the string that I supposedly want, but don't know for sure.
So lets say I have a text file called test.txt and the first line in it looks like this:
1 2 3 4 5 6 7 8 9 10
Now I want to parse this line into different variables, and I really want to know what the 5th item in this line is. In this case, looking at the file, I could tell you it is "5", but how to do in VDS, and say send it to and Info line??
Can someone help me understand this? PLEASE!! And evidently in Kindergarden-VDS! 'Cause I don't get VDS-101!!
Thanks in advance.
Rod |
|
| Back to top |
|
 |
uvedese Contributor


Joined: 21 Jan 2006 Posts: 169 Location: Spain
|
Posted: Sun Nov 25, 2007 8:48 am Post subject: |
|
|
Hi kc7aad:
I see that you are a little tied...
In the first line in your txt file: 1 2 3 4 5 6 ... the arguments are separated by spaces, them, you must indicate to VDS the field separator character (default is |). I suppose that you have loaded the txt file in the list 1.
| Code: | option fieldsep,@chr(32)
parse "%1;%2;%3;%4;%5",@item(1,0)
option fieldsep,|
# Default field separator charapter |
Now the variable %5 contains the fifth argument.
Good luck
______________
uVeDeSe
______________
visit: http://www.uvedese.es
Last edited by uvedese on Wed Apr 02, 2008 7:25 pm; edited 1 time in total |
|
| Back to top |
|
 |
DaveR Valued Contributor


Joined: 03 Sep 2005 Posts: 413 Location: Australia
|
Posted: Sun Nov 25, 2007 9:09 am Post subject: Re: I just can't grasp PARSE!! |
|
|
| kc7aad wrote: | I use
PARSE "%1,%2,%3,%4",%5
BUT WHAT DO THEY MEAN?? I think %5 is the piece of the string that I supposedly want, but don't know for sure. |
Rod,
%5 in your example holds the string that you want to parse.
Try this:
| Code: | %%string = one|two|three
option fieldsep,|
parse "%1,%2,%3",%%string
info %1 @cr()%2 @cr()%3
|
%1 now = one
%2 now = two
%3 now = three _________________ cheers
Dave |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Sun Nov 25, 2007 4:54 pm Post subject: |
|
|
| Code: | | parse "%1,%2,%3",%%string |
The reason the %1,%2,%3 should be between quotes is that the VDS interpreter has to read the names of the variables so it can put the parsed data inside the correct variables. Because of the quotes the variables will be read as text insteed of replaced by their values. _________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|
| Back to top |
|
 |
kc7aad Contributor

Joined: 09 Oct 2005 Posts: 53 Location: Spokane Washington
|
Posted: Mon Nov 26, 2007 5:17 am Post subject: |
|
|
| Thanks Guys!! I was on the right track, just had some syntax wrong, and it wasn't workign quite the way I thought it should. |
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Mon Nov 26, 2007 5:45 am Post subject: Re: I just can't grasp PARSE!! |
|
|
Edit: Sorry, I see you respoded while I was writing this but maybe it will help someone else
Edit 2: OM*G Uvedese, I never until now noticed the additional options in the @Item() function.
| From the help file wrote: | | "The optional second parameter of @ITEM (i, x) allows you to retrieve an item from a list randomly without having to seek to that item first." |
| kc7aad wrote: |
So lets say I have a text file called test.txt and the first line in it looks like this:
1 2 3 4 5 6 7 8 9 10
Now I want to parse this line into different variables, and I really want to know what the 5th item in this line is. In this case, looking at the file, I could tell you it is "5", but how to do in VDS, and say send it to and Info line??
Rod |
Let's create an example based on the criteria you provided.
| Code: | REM Create a list to hold test.txt
List Create,1
REM Normaly the next line would be "List Loadfile,1,<path to test.txt>"
REM But we will instead simulate it for this example
List add,1,"1 2 3 4 5 6 7 8 9 10"
REM Since you stated the above was the first line we need to set the
REM index pointer of list "1" to the first line
List seek,1,0
REM Since there is a <space> separating your numbers we set the
REM separater as a <space> which in ASCII is 032 (The default is a vertical bar "|" eg. 1|2|3|4|5|etc...)
REM The VDS equivilent for a space is @chr(32)
REM You might even be able to use a space with quotes at each end " "
REM Here are some common separaters(aka delimiters) @tab() @chr(32) ";" ":" "," "|"
Option Fieldsep,@chr(32)
REM Next we parse the string in list "1" that is at the current index.
REM The list of variables you want to use must be separated by a semicolon ";" and
REM enclosed with quotes so that VDS sees them as variable names instead if their values.
REM VDS will then fill each variable with the contents of each field respectfully.
Parse "%1;%2;%3;%4;%5;%6;%7;%8;%9;%A", @item(1)
REM Let's see what we got...
Info "%1" = %1@cr()"%2" = %2@cr()"%3" = %3@cr()"%4" = %4@cr()"%5" = %5@cr()"%6" = %6@cr()"%7" = %7@cr()"%8" = %8@cr()"%9" = %9@cr()"%A" = %A
REM Alternately, you could just get the fifth field if that's all you need.
Parse ";;;;%%ThisOneOnly",@item(1)
Info "%%ThisOneOnly" = %%ThisOneOnly
Exit |
I hope that was Kindergarden enough for you
Have fun |
|
| 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
|
|