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
Printable View
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
here i found this code
I am calling the function as followsCode: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);
}
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 ???Code:char FinalFileString[99999];
replstrr(pszFileText, "\n", "\r", FinalFileString);
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
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
Try this, it won't nessesarily need the strings to be on heap, and runs in linear time.
PHP Code:char* replacestr(const char* str,const char* crt,const char* rep,char*trg){
char* temp=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;
};
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 );
}
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 ??
Take a look at the SelectObect function
SelectObject()
it has no effectCode: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);
Did you say you were using a Rich Edit control?
Take a look at this Rich Edit message
EM_SETCHARFORMAT