1
4

2 回答 2

1

Here is a simple example how to get lines from a GtkTexBuffer.

  GtkTextIter start_iter, next_iter;
  gchar *text;

  gtk_text_buffer_get_iter_at_offset (source_buffer, &start_iter, 0);

  next_iter = start_iter;
  while (gtk_text_iter_forward_line (&next_iter))
    {    
      text = gtk_text_iter_get_text (&start_iter, &next_iter);

      // line processing

      g_free (text);
      start_iter = next_iter;
    }    

For more details read the documentation of GtkTextIter.

于 2012-05-17T06:42:31.637 回答
0

You can split the string into an array of strings, one for each line. Use g_strsplit(). However, if you want to relate your data back to the position in the buffer, you're better off using buffer iterators.

于 2012-05-18T08:29:28.830 回答