pattern counting

mchinnansm

New Member
hi ..
greetings...

i want to know that the number of times of a particular word exists in a line.
i tried with index,begins lookup.it gives the first letter only.

but i want to check the "word" in a passage.
can help....


thanks...:D
 
hi ..
greetings...

i want to know that the number of times of a particular word exists in a line.
i tried with index,begins lookup.it gives the first letter only.

but i want to check the "word" in a passage.
can help....


thanks...:D

Maybe this will help you a little :lol:

Code:
FUNCTION WordCount      RETURNS INTEGER
    (icWord AS CHARACTER,
     icLine AS CHARACTER):

    DEFINE VARIABLE iWordCount  AS INTEGER    NO-UNDO.
    DEFINE VARIABLE cTemp       AS CHARACTER  NO-UNDO.
    DEFINE VARIABLE iPosition   AS INTEGER    NO-UNDO.
    
    CASE icWord:
        WHEN "*" THEN ASSIGN iWordCount = NUM-ENTRIES(icLine," "). /* All words */
        OTHERWISE DO:
            ASSIGN cTemp     = icLine
                   icWord    = icWord + " "
                   iPosition = 1.
            DO WHILE iPosition <> 0:
                ASSIGN iPosition = INDEX(cTemp,icWord).
                IF iPosition > 0 THEN
                DO:
                    ASSIGN iWordCount = iWordCount + 1.
                    ASSIGN cTemp = SUBSTRING(cTemp,iPosition + LENGTH(icWord)).
                END.
            END.
        END.
    END CASE.
    RETURN iWordCount.
END FUNCTION.
 
MESSAGE WordCount("*","It is awfull weather isn't it" )
    VIEW-AS ALERT-BOX INFO BUTTONS OK.
 
MESSAGE WordCount("is","It is awfull weather isn't it" )
    VIEW-AS ALERT-BOX INFO BUTTONS OK.
 
hi mchinnansm,
i think you want to count some pattern occurs how many times. for example how many "hi" in a line.

here is a quick and dirty code.

Code:
def var i as char.
def var what_word as char.
def var word_length as integer.
def var k as integer.
def var j as integer.
j = 0.
i = "mbsm hi mbsm what".
update what_word with frame a centered side-labels.
word_length = length(what_word).
do k = 1 to length(i):
if substring(i,k,word_length) = what_word then
do:
j = j + 1.
end.
end.
display j.

if u give mbsm as what_word it displays 2.

regards,
Bala
 
Back
Top