Results 1 to 10 of 10

Thread: Search And Replace ??

  1. #1

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    Search And Replace ??

    How would I search for a certain character in a variable and replace it with another character....

    for example how would i search for a linefeed and replace it with a CarriageReturn ??

    Thanx
    AAG
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  2. #2

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    doesn't anybody wanna take a crack at it ??

    here i found this code

    Code:
    int replstrr(const char *str, const char *sch, const char *rpl, char *tgt);
    
    int replstrr(const char *str, const char *sch, const char *rpl, char *tgt)
    {
    	const char *p = NULL;
    
    	if (str == NULL || tgt == NULL) 
    	{
    		return(1);
    	}
    	for (p = str; *p; ++p) 
    	{
    		if (strncmp(p, sch, strlen(sch)) == 0) 
    		{
    			strcat(tgt, rpl);
    			p += strlen(sch) - 1;
    
    		} 
    		else 
    		{
    			strncat(tgt, p, 1);				
    		}
    	}
    	return(0);
    }
    I am calling the function as follows

    Code:
    char FinalFileString[99999];
    			   
    replstrr(pszFileText, "\n", "\r", FinalFileString);
    it finds the linefeeds and replaces them with Carriage returns yet the textbox that i'm sending FinalFileString to still reads the Carriage Return as a symbol and not a an Actual Carriage Return... How do i fix this ???
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  3. #3

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    i also know that the ascii equvialents of LineFeed and CarriageReturn are as follows,

    0xA = Line Feed

    0xD = Carriage Return

    i know how to do what i need to do in visual basic and in case u want to know, a line feed in visual basic is chr$(10) and a carriage return is chr$(32) or vbcrlf
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    strncat copies the string each time you call it, which means your algoritm is quadratic, and get's freakin slow with longer strings. I'll be back with a linear algoritm
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Try this, it won't nessesarily need the strings to be on heap, and runs in linear time.
    PHP Code:
    charreplacestr(const charstr,const charcrt,const charrep,char*trg){
        
    chartemp=trg;
        for(;*
    str; ){
            for(const 
    char*i=crt,*j=str;*j&&*i&&*i==*j;j++,i++);
            if (!*
    i){
                for(
    i=rep;*i;*trg++=*i++)str++;
                
    str=j;
            }else 
                *
    trg++=*str++;
        }
        *
    trg=0;
        return 
    temp;

    }; 
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    amac
    Guest
    Are you trying to do this without using the standard string functions?

    because if not... wouldn't it be easier to do something like this

    Code:
    char* replacestr(const char* str,const char* crt,const char* rep,char*trg)
    {
    
        strcpy ( trg, str );
    
        char * pos = strstr ( trg, str );
    
        if ( pos != NULL)
            *pos = *crt;
    
        return ( trg );
    
    }

  7. #7

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    aight coo in fact that might not be neccessary if i can figure out how to change the the font format for the whole RichEdit Window... the richedit recognizes all linefeeds as for what they are and not as symbols but i need to set the font to Terminal.... any idea how ??
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  8. #8
    amac
    Guest
    Take a look at the SelectObect function

    SelectObject()

  9. #9

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    ok i tried this

    Code:
        HFONT hTheFont;
        HDC hDC = GetDC(RichHwnd);
    
        hTheFont = CreateFont(9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH, "Terminal");
    
    	SelectObject(hDC, hTheFont);
        
    	ReleaseDC(RichHwnd, hDC);
    it has no effect
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  10. #10
    amac
    Guest
    Did you say you were using a Rich Edit control?

    Take a look at this Rich Edit message

    EM_SETCHARFORMAT

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width