-
Oct 27th, 2001, 07:50 AM
#1
Thread Starter
Hyperactive Member
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)
-
Oct 27th, 2001, 10:43 AM
#2
Thread Starter
Hyperactive Member
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)
-
Oct 27th, 2001, 10:47 AM
#3
Thread Starter
Hyperactive Member
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)
-
Oct 27th, 2001, 03:16 PM
#4
transcendental analytic
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.
-
Oct 27th, 2001, 04:09 PM
#5
transcendental analytic
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;
};
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.
-
Oct 27th, 2001, 04:25 PM
#6
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 );
}
-
Oct 27th, 2001, 04:27 PM
#7
Thread Starter
Hyperactive Member
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)
-
Oct 27th, 2001, 04:31 PM
#8
Take a look at the SelectObect function
SelectObject()
-
Oct 27th, 2001, 04:42 PM
#9
Thread Starter
Hyperactive Member
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)
-
Oct 27th, 2001, 04:52 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|