Thread: Extracting text

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    167

    Extracting text

    I wrote this incorrectly
    Last edited by Paul22000; 04-11-2009 at 11:39 PM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The problem is that you want to keep some delimiters (like the special characters), but not others (like spaces). I would write my own function for this.

    Code:
    char buffer[100];
    unsigned int buffer_index = 0;
    for(const char* p = string_to_parse; *p; ++p)
    {
        switch(*p)
        {
        case '<':
        case '>':
        case '|':
        case '&':
            if(buffer_index > 0)
            {
                buffer[buffer_index] = '\0';
                create_string_token(buffer);
                buffer_index = 0;
            }
            create_char_token(*p);
            break;
        case ' ':
            buffer[buffer_index] = '\0';
            create_string_token(buffer);
            buffer_index = 0;
            break;
        default:
            /* Normal character */
            buffer[buffer_index++] = *p;
        }
    }
    This should give you an idea where to start. It parses through the string looking for tokens. You still need to take the token characters and strings, and add them to your completed array. The code above should only be used as a blueprint; it's probably buggy

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble drawing text xlib.
    By Qui in forum Linux Programming
    Replies: 1
    Last Post: 05-10-2006, 12:07 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 09:52 PM
  4. Scrolling The Text
    By GaPe in forum C Programming
    Replies: 3
    Last Post: 07-14-2002, 04:33 PM
  5. Replies: 1
    Last Post: 07-13-2002, 05:45 PM