Re: [Vala] array size determining? how to



On 09/18/2010 06:50 PM, Evan Nemerson wrote:
On Sat, 2010-09-18 at 18:33 -0700, Charles Hixson wrote:
On 09/18/2010 03:05 PM, Evan Nemerson wrote:
On Sat, 2010-09-18 at 14:09 -0700, Charles Hixson wrote:

When an array is passed back from a library routine, say string split,
how does one determine the number of elements?

Arrays have a length member which will generally give you what you want.
For example:

var arr = "one,two,three".split (",");
GLib.debug ("Elements: %d", arr.length);

There is some good information in the Arrays section of the tutorial:
http://live.gnome.org/Vala/Tutorial#Arrays


-Evan

Thanks.  Is there some place I should write to suggest that this be
added to the tutorial?  I'd also like to suggest that when strings are
Not really, but the tutorial is a wiki so you can always add it
yourself. That said, it is already in the tutorial... the second
sentence in the Arrays section is: "The length of such an array can be
obtained by the length member variable e.g. int count = a.length."


-Evan
Right you are. I guess what I really wanted is a concise table of operations on arrays. E.g., the operator "in" is defined somewhere, I have no idea whether it works on arrays or not. (Well, actually my guess is that it doesn't, but it wouldn't surprise me to find I was wrong.)

But... is there reasonable editorial oversight of the Wiki? I'm hesitant to enter things at my stage of ignorance for fear of making mistakes.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]