5 Replies Latest reply on Oct 15, 2010 4:58 PM by moonyounglee

# how can i get the word's number in the sentence?

### Title

how can i get the word's number in the sentence?

### Post

hi, everyone

i have a problem about checking number of specific word.

for example, " I have a apple."

in that sentence, word "apple" is 4th word from first.

how can i get number "4" ?

• ###### 1. Re: how can i get the word's number in the sentence?

Use the Position(text;searchString;start;occurrence) function to find if the word is in your string and where it starts.

next use the Left(text;numberOfCharacters) to select all of the string before the occurance of your word set numberof characters to Position -1

next use the  WordCount(text) function to count how many words are in the new string which will be on less than your word position

the formula would end up as WordCount(Left(text;Position(text;searchString;start;occurrence)-1) )+1

WordCount(Left(" I have a apple.";Position(" I have a apple.";apple;1;1)-1) )+1

I have not tested this but I believe it will work.

Ian

• ###### 2. Re: how can i get the word's number in the sentence?

Seems like a good use of a recursive custom function:

http://www.briandunning.com/cf/474

• ###### 3. Re: how can i get the word's number in the sentence?

Using a global to hold the varying word you are looking for, as Ian suggested, you could use:

Let ( [
pos = Position ( text ; gWord ; 1 ; 1 ) ;
prior = Left ( text ;  pos - 1 ) ]  ;
WordCount ( prior )
)

• ###### 4. Re: how can i get the word's number in the sentence?

Keep in mind that you CAN get false positives and you should clearly decide the business rules, i.e. if you are looking for 'right' and there is a word rightful, it will identify it as a match and count words before it.  But since you are looking for the count of words before this word, it should be fine.

• ###### 5. Re: how can i get the word's number in the sentence?

thank everybody..

thank...