Count the number of occurences.

Posted by ithrees.ai on 14-May-2012 01:54

Hi All,

I have situation that I need to count the number of occurences of an specific word from a big string field.

Can anyone help me with this...?

Thanks

All Replies

Posted by nidk on 14-May-2012 02:36

for perfomance and utilities you need use C# methode with Regex expression.

Also in ABL pure code , you mays try this

do i = 1 to   num-entries (myvar," "):

   if (entry(myvar,i," ") == myword) then j = j + 1.

end.

Posted by Admin on 14-May-2012 02:46

It all depends on the grammar... If words are allowed to follow a period or a comma, entry is going to fail. INDEX and LENGTH would be the functions of choice in this likely case.

Posted by ithrees.ai on 14-May-2012 04:39

Thanks Adrien and Mike,

I think I got this,

/*-------------------------------------------------------------------------------*/

DO WHILE TRUE:
    IF INDEX (SourcText, WordToFind, Position) > 0 THEN
    DO:
      ASSIGN
        Position = INDEX (SourcText, WordToFind, Position) + 1
        Counts   = Counts + 1.
    END.
    ELSE
      LEAVE.
END.

DISP Counts.

/*-------------------------------------------------------------------------------*/

any suggestions..?

Posted by jmls on 14-May-2012 04:41

this would break with the following:

say that you are looking for the word "foo"

"foo this is more text foo. And this is foobar"

would return a count of three. But foobar is not foo

Julian

On 14 May 2012 10:39, Ithrees Asan Ishak

This thread is closed