[Gambas-user] Function to count substrings

Gianluigi bagonergi at ...626...
Wed Sep 13 13:41:27 CEST 2017


Hi Rolf,
I do not think it exists, but it can be done by myself. :-)
As I wrote, I would do so:

Private Function CountSubString(value As String, pattern As String,
Optional compare As Integer) As Integer '' compare default Sensitive, 1 =
Insensitive

  Dim i, n As Integer

  While i <= Len(value)
    i = InStr(value, pattern, i + 1, compare)
    If i = 0 Then Break
    Inc n
  Wend
  Return n

End

Any ideas better?

Regards
Gianluigi

2017-09-13 11:42 GMT+02:00 Rolf-Werner Eilert <rwe-sse at ...3629...>:

> Thank you Luigi,
>
> This is what I had programmed myself (more or less). I just thought there
> might be a ready-made function like CountStr() or StrCtr() or something :)
>
> Regars
> Rolf
>
>
> Am 13.09.2017 11:01, schrieb Gianluigi:
>
>> Sorry the link to see it work is this :-(
>> https://gambas-playground.proko.eu/?gist=d0fc775a24c00f2d5271865a565739ef
>>
>> Regards
>> Gianluigi
>>
>> 2017-09-13 10:53 GMT+02:00 Gianluigi <bagonergi at ...626...>:
>>
>> And something like that?
>>> https://gist.github.com/anonymous/d0fc775a24c00f2d5271865a565739ef
>>>
>>> Regards
>>> Gianluigi
>>>
>>> 2017-09-13 10:04 GMT+02:00 Rolf-Werner Eilert <rwe-sse at ...3629...>:
>>>
>>> Thanks Julio,
>>>>
>>>> good idea! - but: isn't this a bit too much? After all, you have to
>>>> instantiate a string[] for it each time, even though you don't see it.
>>>> Or
>>>> am I wrong? At least when it has to be called many times (for a table
>>>> like
>>>> in my case).
>>>>
>>>> Regards
>>>> Rolf
>>>>
>>>>
>>>> Am 13.09.2017 09:32, schrieb Julio Sanchez:
>>>>
>>>> Hi Rolf:
>>>>>
>>>>> "how many times does ......"
>>>>> Maybe this may be worth this:
>>>>>
>>>>> count=split(mystring,chr$(10)).count
>>>>>
>>>>> Regards,
>>>>> Julio
>>>>>
>>>>> 2017-09-13 9:18 GMT+02:00 Rolf-Werner Eilert <rwe-sse at ...3629...>:
>>>>>
>>>>> Hi folks,
>>>>>
>>>>>>
>>>>>> Somehow I don't remember this - wasn't there a function to count the
>>>>>> number of substrings occuring within a string?
>>>>>>
>>>>>> For instance, how many times does myString contain chr$(10) (to count
>>>>>> the
>>>>>> number of linefeeds). So it would be a blend of Instr() and String$().
>>>>>>
>>>>>> Thanks for your input!
>>>>>>
>>>>>> Regards
>>>>>> Rolf
>>>>>>
>>>>>> ------------------------------------------------------------
>>>>>> ------------------
>>>>>> Check out the vibrant tech community on one of the world's most
>>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>>>>> _______________________________________________
>>>>>> Gambas-user mailing list
>>>>>> Gambas-user at lists.sourceforge.net
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>>> ------------------------------------------------------------
>>>>>>
>>>>> ------------------
>>>>> Check out the vibrant tech community on one of the world's most
>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>>>> _______________________________________________
>>>>> Gambas-user mailing list
>>>>> Gambas-user at lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>>
>>>>>
>>>>>
>>>> ------------------------------------------------------------
>>>> ------------------
>>>> Check out the vibrant tech community on one of the world's most
>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>>> _______________________________________________
>>>> Gambas-user mailing list
>>>> Gambas-user at lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>>>
>>>
>>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>>
>>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list