On Jul 5, 9:26pm, Steve Elmer wrote:
> Subject: Re: Word extraction CI evaluator function
snip...
> : Example:
> : setvar buffer input()
> : setvar i 1
> : while i <= len(buffer) do
> : setvar next_word word(buffer,i,,i)
> : if next_word = "..." then ...
>
> comment: don't forget the increment!
The variable i is set, by word(), to the index of the character that delimited
the word, or if it is the last word, to len(buf)+1. Also, in my example, i
is used as the starting index too.
> setvar i i+1
>
> : endwhile
>
> This loop doesn't work the way you think it does based on the description.
1234567890
> If buffer = "a b cd efg", then each iteration would get the following values:
>
> comment index 1, word 1
> a
yes
> comment index 2, word 2
> cd
no, index=2 from prior word() call, the blank is skipped and word="b" and
index is set to 4 when word() returns.
> comment index 3, word 3
> efg
no, index=4 from prior call, blank is skipped, word="cd" and index is set to 7.
> comment index 4, word 4
> ??? what comes back when there is no such word?
index=7 from prior call, blank is skipped, word="efg" and index is set to 11,
11 is len(buf)+1, which I didn't mention. Now the while loop will end.
I apologize for the poor description. I am interested in knowing which of
the last 3 parameters (nth, rtn_var, delims) are most useful so I can
define them in the best ordering.
> It seems to me that the function should return a null string when it can't
> find the expected word.
Yes, it will.
snip...
> How about a word count function too?
I hadn't thought of that. Can a few people give me examples of how they would
use a word_cnt() function? Thanks.
Jeff Vance
--
|