Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion wordposAtIndex() / wordAtIndex(): find the number of the word at a given index position

Received: by 10.180.82.226 with SMTP id l2mr2498981wiy.1.1346168683143;
        Tue, 28 Aug 2012 08:44:43 -0700 (PDT)
Path: e9ni58568275wia.0!nntp.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From: "Dave Saville" <d...@invalid.invalid>
Newsgroups: comp.lang.rexx
Subject: Re: wordposAtIndex() / wordAtIndex(): find the number of the word at a given index position
Date: Tue, 28 Aug 2012 15:44:42 +0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <fV45K0OBJxbE-pn2-gure3IoEbN43@localhost>
References: <81a1c884-036c-4b03-bfb9-1dafa40416b3@googlegroups.com>
Mime-Version: 1.0
Injection-Date: Tue, 28 Aug 2012 15:44:42 +0000 (UTC)
Injection-Info: mx04.eternal-september.org; posting-host="12f6f2e2d96e1c0fe9cc474ffed8cc8b";
	logging-data="29388"; mail-complaints-to="ab...@eternal-september.org";	posting-account="U2FsdGVkX19etiU03XH93w+cCfoCTlfH"
User-Agent: ProNews/2 V1.60.cp125
Cancel-Lock: sha1:Zg4LzjpM7jNZnNhlsh/lVeWB0HQ=
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit

On Tue, 28 Aug 2012 14:22:37 UTC, muk...@gmail.com wrote:

> I am looking for a function that would return the number of a word at a given index position.
> 
> Example: assuming function syntax is wordposAtIndex(n, haystack)
> 
> wordposAtIndex(10, "Georg Friedrich H„ndel, a great componist") should return "3"
> 
> This way I can retrieve the word at that given index or perform other word proximity processing for that matter. The index would generally result from a rexx pos() or a regular expression match.

string = "Georg Friedrich H„ndel, a great componist"
n = 17
do i = 1 to words(string)
  x = wordindex(string, i)
  if x >= n then do
    say word(string, i) i
    leave;
  End
End

Never got the hang of REXX functions but you get the idea. But, what 
about if n hits punctuation or white space - which way do you jump?

-- 
Regards
Dave Saville