Text extraction

This is a discussion on Text extraction within the C Programming forums, part of the General Programming Boards category; Hi, I ahve a long string of which I want to remove certain words.... for example: string example =" <this> ...

  1. #1
    Unregistered
    Guest

    Angry Text extraction

    Hi,
    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 "<>"...so after my programs runs I would be left with

    <"is some data">

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

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    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
    Posts
    34
    Try this. Keep in mind, the code will modify the string directly.

    Code:
    #include <string.h>
    
    void RemoveWords(char *str);
    
    int main(int argc, char* argv[])
    {
    	char str[81];
    
    	strcpy(str, "<this> is some <test> data");
    
    	RemoveWords(str);
    
    	return 0;
    }
    
    void
    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++;
    			}
    			t++;		// skip the END_CHAR
    		}
    		
    		*p = *t;		// finally, copy the current character
    		p++;
    		t++;
    		
    		if (*t == '\0')
    			*p = '\0';
    	}
    }
    Last edited by clu82; 02-27-2002 at 03: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21