In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

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

Xailer professional forum in English
Responder
ChrisGillard
Mensajes: 384
Registrado: Mar May 01, 2007 5:49 pm

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

Mensaje 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
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9252
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

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

Mensaje 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,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
Responder