Using FS, GS, RS and US (was A question about certain ASCIIcharacters...)
Lynch, Jonathan
bnz2 at cdc.gov
Wed May 11 13:48:45 EDT 2005
I pretty much just switch the itemdelimiter back and forth between FS,
GS, RS, and US
Imagine that I had stored data for a card with 4 fields into a text
file, and the fourth field of that card contained data for a table, and
I wanted to take that table data and put it into an array. The script
would look something like this:
On LoadTable
Put numtochar(28) into L1
Put numtochar(29) into L2
Put numtochar(30) into L3
Set the itemdelimiter to L1
Put item 4 of URL (my text file) into tData
Set the itemdelimiter to L2
Put 0 into L2Count
Repeat for each item tRow in tData
Add 1 to L2Count
Set the itemdelimiter to L3
Put 0 into L3Count
Repeat for each item tCell in tRow
Add 1 to L3count
Put tCell into myArray(L2Count, L3Count)
End repeat
Set the itemdelimiter to L2 --*
End repeat
--(from here, do whatever I wanted to do with myArray)
End LoadTable
*Note that for nested repeat for each item loops, after the inner loop
is finished, it is necessary to set the itemdelimiter back to whatever
you use for the itemdelimiter of the outer loop. Without this, it gets
confused and tries to read cells as rows, and your array becomes
gobblydegookicized. You can have any number of nested levels of repeat
for each item loops, as long as you are careful to reset the
itemdelimiter back to what it needs to be at the end of each loop.
I usually use numtochar(28) as a separator between top-level fields and
top-level groups, numtochar(29) to separate between rows (which for me
would be second-level groups stored in a top-level group), numtochar(30)
as a separator between cells (which for me would be fields stored in
those second-level groups), and numtochar(31) as a delimiter to use
within a cell (for example, item 1 within a cell might contain
information about the properties of a field, and item 2 within a cell
might contain the htmltext of a field)
If I need even more itemdelimiters, I have used the vertical tab
character (numtochar(11)) and the substitute character (numtochar(26)).
I have been scared to use the other lower ascii codes because they sound
like they might do things that would activate various bits of computer
hardware, or be things that are used within the system (such as the end
of text character).
By using nested repeat for each item loops with these delimiters, I do
not have to worry if the fields that are being stored as cells contain
linefeeds, commas, spaces, or any other thing that could throw off the
information if I were using repeat for each line loops, repeat for each
word loops, or comma-delimited repeat for each item loops.
>(BTW, there is no 2 in ASCII, pronounced as as-Key
>according to my worn 1977 copy.)
I think I knew that (somewhere in the back of my cobwebbed brain), I
just got the notation confused with other acronyms that use for work:)
-----Original Message-----
From: use-revolution-bounces at lists.runrev.com
[mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of Dar Scott
Sent: Wednesday, May 11, 2005 12:48 PM
To: How to use Revolution
Subject: Using FS, GS, RS and US (was A question about certain
ASCIIcharacters...)
On May 11, 2005, at 7:28 AM, Lynch, Jonathan wrote:
> I like to use ascII characters 28-31 as item delimiters. These are
> characters that are actually set aside for this purpose within the
> ascII
> character set.
Intriguing idea!
(BTW, there is no 2 in ASCII, pronounced as as-Key according to my worn
1977 copy.)
For those wondering what he's talking about:
Characters decimal 28 through 31 of the control characters of ASCII
have the names FS (file separator), GS (group separator), RS (record
separator) and US (unit separator). There are no semantics defined,
only that those on the left are bigger than those on the right.
Do you ignore Transcript items and lines or are they integrated into
that hierarchy?
Perhaps a hierarchy can be like this:
array (where allowed)
file (this name might cause confusion)
group
record
unit
line
item
word ?
Anybody else do this kind of thing?
Dar
--
**********************************************
DSC (Dar Scott Consulting & Dar's Lab)
http://www.swcp.com/dsc/
A pig's gotta fly. -- Porco Rosso
**********************************************
_______________________________________________
use-revolution mailing list
use-revolution at lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution
More information about the use-livecode
mailing list