Re: Newbie questions, text processing, for each etc.

Jeremy West - UK Technical Training Manager (starnet!apple!UK.Sun.COM!Jerry.West)
Wed, 30 Mar 1994 09:28:42 +0000

Greg Zhang asks... and although I'm not certain of the answers, here I go:

-> read from file|process <name> until numToChar(10)
-> put It into field <field_name>
->
-> keeps '\n' in <field_name>. How do I truncate '\n' out?

in this case: delete the last character of It

in general: put offset(return, It) into rp # numToChar(10) if needed
delete character rp of It # first occurrance only

-> - How to do "for each card"?

repeat with i = 1 to the number of cards in this stack
<process card i>
end repeat

-> - Text processing
->
-> I've read from some posts that to do text processing, you first read
-> a whole bunch of text into a variable, then read from the variable chunk
-> by chunk to do your processing. I am not clear how this is accomplished.
-> How do you read from a variable? It appears to me that the only string
-> functions in Metacard/HyperCard are is and contains. These two are far
-> less than enough to do any real string manipulation.

You read from a variable using get and set it using put.

There are lots of "chunk" expressions to process text, e.g.

get the first word of field "fieldname"
delete character 1 to 8 of myContainer
put line 3 of field "f" into container

However, these are all word-oriented for use on genuine text; for much of
what I want to do, the text is not ammenable to word-processing, what I
really do miss is a tr(1) or substitute; to replace all occurrences of (eg)
space with (eg) dash you have to do this...

put offset(space, it) into op
repeat until op = 0
delete character op of it
put "-" before character op of it
put offset(space, it) into op
end repeat

and I'd MUCH RATHER say (hint to Scott)

substitute "-" for space in It # first occurrance
substitute "-" for space throughout It # all occurrances

Even better would be REGULAR EXPRESSIONS! (more hints)

By the way: I recommend buying a generic HyperCard book/tutorial since it
will explain a lot which the MetaCard docs assume you already know. I use
The Complete HyperCard Handbook (3rd Edition). It provides a good introduction
to the concepts and capabilities of HyperCard (and by extension, MetaCard).

However, in order to use both the CHH(3E) and the Metacard docs as a reference
work, you have to know what you're looking for - so it's very difficult to find
out whether a capability exists unless you know what it's called. You may find
some HyperCard "cookbooks" will help here.

Hope this helps some, caveat experimentor, though, the above is untested and
I may have mispelt or misplaced bits :-(.

Cheers,
Jerry