Steven D'Aprano wrote:
> > If you have a field that says the following:
> > The man said, "I cannot live on bread alone."
>
> > ...and you ask MetaCard for word 4 of the field, you get the whole
> > entire text string between the quotes
>
> This is a (mis-)feature required for Hypercard compatability. Frankly
> I'm not sure why the HC designers thought it was neccessary in the first
> place.
If you want to parse natural language, it is a reasonable design
decision to count quoted phrases as a single word... but I don't want to
start a flame war. Words in xTalk are not what they are in natural
English. They may even include characters that are not what you'd
consider being part of a word: "don't try this at home!" is split up
into "don't", "try", "this", "at", and "home!". But in English you'd
split it like: "do", "not", "try", "this", "at", and "home". Now think
of other uses of the apostrophe... you'd need quite some intelligence
and in other languages things may even get more complicated.
> I have two possible solutions. Firstly, you might like to try setting
> the item delimiter to space and asking for items instead of words. I
> haven't actually tested this myself in Metacard, but I've played with it
> in HC and it works. But be warned that end of lines also delimit words,
> but they won't if you use space-delimited items.
This is propably not acceptable.
> Secondly, if your handler can be adapted to this format, you could try
> something like this:
>
> on ProcessRealWords theText
> for j = 1 to the number of words of theText
> put word j of theText into theWord
> if theWord contains space then
> -- a quoted "word" or phrase
> ProcessRealWords theWord -- call myself recursively
> else -- a real word delimited by whitespace
> DoStuff theWord
> end if
> end repeat
> end ProcessRealWords
>
> The nice thing is that quoted words cannot contain other quoted words,
> so the handler will only call itself at most once per iteration.
Why not use something like:
on getWord n,txt
put txt into txt2
replace quote with "'" in txt2
put the number of chars in word 1 to n-1 of txt2 into pos
put the number of chars in word n of txt2 into len
return char pos+1 to pos+len of txt
end getWord
Regards
R�diger
--------------------------------------------------------------------
| Ruediger zu Dohna GINIT GmbH 0721-96681-63 [EMAIL PROTECTED] |
| PGP-Fingerprint: F1 BF 9D 95 57 26 48 42 FE F8 E8 02 41 1A EE 3E |
--------------------------------------------------------------------