GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strip markup in a string

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code
Author Message
Vadi
GTK+ Geek


Joined: 28 May 2008
Posts: 68

PostPosted: Wed Jun 25, 2008 1:20 pm    Post subject: Strip markup in a string Reply with quote

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: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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: (Plaintext)
1
2
3
4
5
6
7
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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP