GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Sep 18, 2014 1:41 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Strip markup in a string
PostPosted: Wed Jun 25, 2008 1:20 pm 
Offline
GTK+ Geek

Joined: Wed May 28, 2008 5:49 pm
Posts: 66
Sometimes you need to strip the markup of a string (like when you want to make the interactive search in GtkTreeView work...)

This function shows you how and also gives an example, all at once!


Code:
void test()
{
    GRegex *pattern;
    gchar *result, *string;

    string =
        g_strdup
        ("<b>GtkPerf 0.40</b>        <span color=\"#737373\"><b>Graphics</b> test, <b>installed</b>\n</span><span color=\"#999999\"><small>This test calculates the average frame-rate from several different GTK operations.</small></span>");

    pattern = g_regex_new(g_strdup("<(.|\n)*?>"), G_REGEX_DOTALL | G_REGEX_OPTIMIZE, 0, NULL);

    result = g_regex_replace_literal(pattern, string, -1, 0, g_strdup(""), 0, NULL);

    printf("string:\n%s\n\nresult:\n%s\n", string, result);

}


Here's the sample output:
[code=]string:
<b>GtkPerf 0.40</b> <span color="#737373"><b>Graphics</b> test, <b>installed</b>
</span><span color="#999999"><small>This test calculates the average frame-rate from several different GTK operations.</small></span>

result:
GtkPerf 0.40 Graphics test, installed
This test calculates the average frame-rate from several different GTK operations.[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group