0

Is there any function to get a substring in GLib?

Something like

gchar *getSlice(const gchar *text, gint startIndex);
Nanne
  • 64,065
  • 16
  • 119
  • 163
BPS
  • 1,133
  • 1
  • 17
  • 38

1 Answers1

4

You can just do:

 gchar *s = &text[start_index];

If you want a copy of the substring, do

 gchar *s = g_strdup(&text[start_index]);

Remember to free the string when you're done with it in the latter case.

nos
  • 223,662
  • 58
  • 417
  • 506