Re: Re[2]: gtk+2.0 text problem



Am Donnerstag, den 18.08.2005, 15:43 +0400 schrieb andrey:
> 
> > Am Donnerstag, den 18.08.2005, 16:03 +0900 schrieb "luft":
> > > i have some question about text.
> > > 
> > > when i press space, i want get token from previous space position to here. 
> > > for example :    aaaa bbbbb  
> > > i wanna get string "bbbbb" 
> > > how can i do that?
> > 
> 
> for example you can do this using sscanf:
> 
> char  s1[30];
> char  s2[30];
> sscanf( tokenstring, "%s %s", s1, s2);

GtkTextIter start_iter;
GtkTextIter end_iter;
char *tokenstring;

gtk_text_buffer_get_start_iter (buffer, &start_iter);
gtk_text_buffer_get_end_iter (buffer, &end_iter);
tokenstring = gtk_text_buffer_get_text (buffer, start_iter, end_iter,
TRUE);

now you have the whole text in the buffer and can sscanf it.

btw: Instead of using fragile, error-prone C functions, I'd rather use
glib code:

char **tokens;
tokens = g_strsplit (tokenstring, " ",
MY_MAX_TOKENS_MAYBE_2_OR_SOMETHING);

If you want to have an entry or text view containing multiple
user-definable keys and want to parse them, you probably want to use
multiple key delimiters.
In that case, you should use g_strsplit_set and pass for instance " ,;
\n" as second parameter.

-- 
Christian Neumair <chris gnome-de org>

Attachment: signature.asc
Description: This is a digitally signed message part



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