https://foro.gambas-es.org/viewtopic.php?f=4&t=8029&p=48356#p48356
-----------------------------------
cogier
Wednesday, 06 May 2020, 15:11

Re: Extendiendo La Clase String
-----------------------------------
Parece que hay algunos errores en su código. Intenta con el siguiente código: -

[code linenumbers=false syntax=gambas]
Public Sub Form_Open()

  Dim sString As String = "Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World"

  Print StrCount(sString, "World")

End

Public Function StrCount(sWhere As String, sWhich As String) As Integer

  Dim i As Integer = 1
  Dim Cursor As Integer
  Dim Counter As Integer

  'i = 1
  Repeat
    Cursor = InStr(sWhere, sWhich, i)
    If Cursor > 0 Then
      Inc Counter
      'i = i + Cursor + String.Len(sWhich)
      i = Cursor + String.Len(sWhich)
    Endif
  Until InStr(sWhere, sWhich, i) = 0 Or i > String.Len(sWhere)
  'Until InStr(sWhere, sWhich, i) = 0 Or i > String.Len(sWhich)
  Return Counter

End
[/code]


