Re: g_strsplit
- From: "Alan M. Evans" <ame1 extratech com>
- To: The Saltydog <thesaltydog gmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: g_strsplit
- Date: Wed, 05 Oct 2005 08:56:10 -0700
On Wed, 2005-10-05 at 07:29, The Saltydog wrote:
This is more related to Glib than to gtk+, but I wonder if anyone can help.
I have an array of strings, created with g_strsplit() function. Then I
need to add another array, also created with the same function, or
some single string.. Is there a shortcut to accomplish this, or should
I play with re-alloc, growing the array by myself? (scared !!)
There aren't enough functions in GLib to make manipulating string arrays
easy. I find that using GPtrArray is easier if I have to actually
manipulate/combine/sort/search the string array.
To get the result of g_strsplit into a GPtrArray, I have used a simple
loop, although I'm certain that this is suboptimal. I don't have to do
it much, so it's not a performance issue for me.
for (i=0; sarray[i]; ++i) g_ptr_array_add(parray,sarray[i]);
When I'm done manipulating the array, I get the string array back:
/* append terminating nulls to string arrays */
g_ptr_array_add(attributes,0);
/* throw away GLib array bookkeeping - keep only array data */
sarray = (gchar**)parray->pdata;
g_ptr_array_free(parray,FALSE);
--
Alan M. Evans <ame1 extratech com>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]