Re: [Vala] How can I sort an array of strings?



Good day Karsten,

Am Donnerstag, den 21.04.2011, 14:22 +0200 schrieb K. König:
I need to sort an array of strings in natural order but the solutions I
found didn't worked for me. I tried this:

    /* Method to fill the array files */
    protected void get_files() {
        string file = "";
        do {
            file = dir.read_name();
            this.files += file;
        } while(file != null);

        /* Cut "null" which was only needed to terminate the loop */
        this.files.resize(files.length-1);
        this.files.sort(strcmp);
    }

'dir' is an opened directory and files is an array of strings (private
static string[] files). I get this message: 'error: The name `sort' does
not exist in the context of `string[]' this.files.sort(strcmp);'

Does anyone know what goes wrong?

Built-in arrays do not provide the .sort function. Try to use Gee.Lists.

- fabian





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