Re: [Vala] removing an element from a list



On Mon, 31 Aug 2009 03:07:57 +0200
Jiří Zárevúcky <zarevucky jiri gmail com> wrote:

On 08/31/2009 03:05 AM, Jiří Zárevúcky wrote:
On 08/31/2009 02:10 AM, jezra lickter wrote:
The word "test" is not removed from the list. Am I doing something
wrong, and is there a better way to do what I need?


The problem is that GLib.List searches for items based on pointer 
value, not the actual data. You have to either use remove_custom or
(a much better possibility) use the Gee collection library. It is
much easier to use from Vala then GLib collection classes, which
were never intended for use in such high-level language.


I meant find_custom()  :) Anyway, Gee is the way to go.
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list

Thanks, the Gee library worked like a charm although I would prefer to
not require another library for the application. If anyone is
interested, the updated code that uses Gee is 

using Gee;
public static void main(string[] args)
{
        ArrayList<string>? al= new ArrayList<string>(str_equal);
        al.add("this");
        al.add("is");
        al.add("a");
        al.add("test");
        //remove the test
        al.remove("test");
        foreach(string word in al)
        {
                stdout.printf("%s ", word );
        }
        stdout.printf("\n");
}



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