Página 1 de 1

Harbour question .... Ocurs() or NumAt() ... or equivalent?

Publicado: Mié Sep 14, 2016 1:26 pm
por ChrisGillard
Hi,

Simple question of a function to count the number of occurrences of a string within another string.

In xHarbour I might use Occurs() but does not seem to exist in Xailer/Harbour.

Yes, I could write something in a couple of lines but like to use the 'official' function where possible.

What do you use?

Thanks.

Chris

Re: Harbour question .... Ocurs() or NumAt() ... or equivalent?

Publicado: Mié Sep 14, 2016 5:12 pm
por ignacio
Hello,

I really do not know if that function exists on Harbour. BTW, this may work:

Código: Seleccionar todo

FUNCTION Occurs( cSearch, cString )

   LOCAL nAt, n := 0
   
   DO WHILE (nAt := HB_At( cSearch, cString, nAt ) ) > 0
      n++
      nAt += Len( cSearch )
   ENDDO
   
RETURN n   
Regards,