Thread: Text extraction

  1. #1

    Angry Text extraction

    I ahve a long string of which I want to remove certain words....

    for example:
    string example =" <this> is some <test> data"

    I want to remove words with are contained with "<>" after my programs runs I would be left with

    <"is some data">

    does anybody have idea's what function I could remove such text from the string...
    any ideas would be great...

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    A for loop and a boolean variable used to control the copying of chars

    You set the bool to false when you see a <
    You set it to true when you see a >

    If it's true, copy the char

  3. #3
    Registered User
    Join Date
    Dec 2001
    Try this. Keep in mind, the code will modify the string directly.

    #include <string.h>
    void RemoveWords(char *str);
    int main(int argc, char* argv[])
    	char str[81];
    	strcpy(str, "<this> is some <test> data");
    	return 0;
    RemoveWords(char *str)
    #define		START_CHAR		'<'
    #define		END_CHAR		'>'
    	char *p;
    	char *t;
    	p = str;
    	t = p;
    	while (*t)			// while we haven't found the end of the string
    		if (*t == START_CHAR)
    			while (*t && *t != END_CHAR) // look for the END_CHAR
    			t++;		// skip the END_CHAR
    		*p = *t;		// finally, copy the current character
    		if (*t == '\0')
    			*p = '\0';
    Last edited by clu82; 02-27-2002 at 04:33 PM.

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. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 09:52 PM
  3. Text positioning and Text scrolling
    By RealityFusion in forum C++ Programming
    Replies: 3
    Last Post: 08-13-2004, 12:35 AM
  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