[Gambas-user] String[].Extract not behaving as expected

Benoît Minisini gambas at ...1...
Thu Dec 4 01:59:37 CET 2014


Le 04/12/2014 01:41, T Lee Davidson a écrit :
> http://gambaswiki.org/wiki/comp/gb/string[]/extract says:
>
> [edited-quote]
> Function Extract (Start As Integer [, Length As Integer ]) As String[]
>
> If Length is negative, then Length elements counting backwards from the
> specified Start are removed.
> [/edited-quote]
>
> But this does not appear to be the manner in which it behaves. (I am
> also unsure what "counting backwards" means. Would that be toward the
> beginning or the end of the array?)
>
> Public Sub Main()
>     Dim myStrings As String[] = ["s1", "s2", "s3", "s4", "s5", "s6", "s7"]
>     Dim sString As String
>
>     myStrings = myStrings.Extract(2, -1)
>     Print "Number of extracted elements: " & myStrings.Count
>     For Each sString In myStrings
>       Print sString
>     Next
> End
>
> produces:
> Number of extracted elements: 5
> s3
> s4
> s5
> s6
> s7
>
> Obviously, "myStrings.Extract(2, -1)" extracted all elements from the
> specified Start to the end of the array, not just one element from the
> specified Start.
>
> "myStrings.Extract(2, -2)" gives an "Out of bounds" error.
>
> So, I guess my question should be, what is the intended behavior?
>
>

The doc is false. -1 means all elements until the end, and other 
negative values have no meaning.

Regards,

-- 
Benoît Minisini




More information about the User mailing list