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


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Sat Dec 14, 2002 11:44 pm Post subject: |
|
|
Instead of parsing the string out, why not replace the fieldsep character with a carriage return @cr() and then assign the string to a string list. Each part of the original string would then be contained on a seperate line within the string list.
Here's an example:
| Code: |
%%fieldsep = @chr(44)
%%sourceString = Line 1,Line 2,Line 3,Line 4
repeat
%p = @pos(%%fieldsep,%%sourceString)
if @greater(%p,0)
%%sourceString = @strdel(%%sourceString,%p)
%%sourceString = @strins(%%sourceString,%p,@cr())
end
until @zero(%p)
if @not(@null(%%sourceString))
list create,1
list assign,1,%%sourceString
info @text(1)
list close,1
end
|
Bill
ShinobiSoft _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it."
Last edited by ShinobiSoft on Sun Dec 15, 2002 12:41 am; edited 3 times in total |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sat Dec 14, 2002 11:47 pm Post subject: |
|
|
I must say, that's a brilliant approach!  |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Dec 15, 2002 12:26 am Post subject: |
|
|
Uh... have ya actually tried that example? _________________ 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 |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Sun Dec 15, 2002 12:30 am Post subject: |
|
|
Not in that exact format. Instead of the %%fieldsep variable, I usually hard code the fieldsep character.
| Code: |
%p = @pos(",",%%sourceString)
.
.
.
|
Bill _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Dec 15, 2002 12:39 am Post subject: |
|
|
My point is - the example doesn't work. Unless you're
trying to lose the last three fields...
BTW, @chr(34) is a quote, but when ya replace it with
@chr(44) (a comma), it still doesn't work.
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 |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sun Dec 15, 2002 12:44 am Post subject: |
|
|
Sorry Mac, I hadn't tried it yet, I wasn't talking about the example, but about the approach.
The error is the line were %%sourceString is assigned to. It should say:
| Code: |
%%sourceString = "Line 1,Line 2,Line 3,Line 4"
|
So the double quotes were missing. |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Sun Dec 15, 2002 12:45 am Post subject: |
|
|
Thanks for pointing out the typeo @chr(34) should have been @chr(44). I've edited my post for this correction.
What I don't understand is why it doen't work for you. It works fine for me. I wouldn't have suggested it if it didn't work!  _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Dec 15, 2002 1:03 am Post subject: |
|
|
OK, it works with the quotes.
But is there a reason ya rather tie up a list than
loop thru and add @chr(34) to the string? Ya could
PARSE it into vars (with meaningful names) then...
Also, any vars used in your example must still be
excluded from the outside 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 |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Sun Dec 15, 2002 1:11 am Post subject: |
|
|
I was just offering an alternative method to parsing information.  _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Sun Dec 15, 2002 1:11 am Post subject: |
|
|
__________________________________________________________________________________________________________________________
It would probably be most simple to just use the following instead of re-inventing the wheel.
| Code: | %%string = @chr(34)Data 1 @chr(34)|@chr(34) Data 2@chr(34)|@chr(34) Data 3 @chr(34)| Data 4
parse "%%data1;%%data2;%%data3;%%data4",%%string
info %%data1;%%data2;%%data3;%%data4 |
_________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sun Dec 15, 2002 2:06 am Post subject: |
|
|
| FreezingFire wrote: | __________________________________________________________________________________________________________________________
It would probably be most simple to just use the following instead of re-inventing the wheel.
| Code: | %%string = @chr(34)Data 1 @chr(34)|@chr(34) Data 2@chr(34)|@chr(34) Data 3 @chr(34)| Data 4
parse "%%data1;%%data2;%%data3;%%data4",%%string
info %%data1;%%data2;%%data3;%%data4 |
|
I disagree, as this method could only be used after the text is parsed. What is the use
of parsing if the text is already parsed? |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Dec 15, 2002 2:15 am Post subject: |
|
|
Didn't he meant add @chr(34) when ya add the
separators to begin with? _________________ 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 |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sun Dec 15, 2002 4:11 am Post subject: |
|
|
Yes but the whole point is that you don't always create the files that you want to read,
so you'll just have to stick with the format that was decided by the file's original author/software. |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Dec 15, 2002 4:25 am Post subject: |
|
|
Quotes are in a lot (if not most) field separated files
anyway. If ya make PARSE include everything between
separators you'd have to have a routine to get rid of
'em on those files.
And ya could loop thru a list (loaded file) and add
@chr(34) just as easy as removing quotes when ya
didn't want 'em...
Or is there a method to have it both ways?
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 8:54 am Post subject: |
|
|
| Mac wrote: | Show 'em on separate lines and it makes more sense
Garrett. Each parsed item is still trimmed because it
doesn't see the quotes...
|
Mac, for me it retained the spaces when I ran that code. At least it did on
VDS 4.x for me.
-Garrett |
|
| Back to top |
|
 |
|