[Gambas-user] String[].Find finds nothing

Tobias Boege taboege at ...626...
Wed May 10 21:38:34 CEST 2017


On Wed, 10 May 2017, Matti wrote:
> Yes. But as I don't know [iIndex], I have to iterate through the (huge) array with 'For...Next'.
> I hoped to make it faster with 'Find'.

You can make the code smaller by using the optional Mode parameter to
String[].Find() (cf. the docs [1]). The following will work as you wanted:

  Dim aNames As New String[]

  aNames.Add("Anna")
  aNames.Add("Berta")
  aNames.Add("Christa")
  aNames.Add("Dora")

  Print aNames.Find("Chr*", gb.Like)
  ' will print 2

but it will probably make the code slower because the gb.Like mode makes the
Find() operation significantly more complex. I would recommend you test it
out though. Also let me say that Gambas can't perform wonders. Just because
you call a single built-in function doesn't make the operation fast. If your
array is huge and unsorted, all searches will be slow. In fact, the Find()
method is implemented as a For-Next loop (in C, admittedly).

Regards,
Tobi

[1] http://gambaswiki.org/wiki/comp/gb/string[]/find

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list