Re: GLib substr function



2009/4/10 b0unc3 <daniele maio gmail com>:
> Hi all,
>
> there is any implementation of a substr function in GLib ?
>
> I mean :
> string = "hello world"
> g_*substr*(string,2,6)
> output = llo w

Another way,

substring (GString *str, int index, int len)
{
  return g_string_new_len (str->str, index, MIN (str->len - index, len));
}

taken from http://bugzilla.gnome.org/show_bug.cgi?id=109286#c2 .


I personally would like that glib provide those small but useful
string functions (like other high level languages do), for example,
glib doesn't provide a simple function to replace strings, like this
one written by Tim in
http://bugzilla.gnome.org/show_bug.cgi?id=65987#c2 ,

gchar *
g_strreplace (const gchar *string,
              const gchar *search,
              const gchar *replacement)


Instead you currently have to use gregex to replace some simple
strings (where no regex are involved).


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