Page 1 of 1
replace NN with NNN
Posted: Fri Jun 25, 2004 11:04 pm
by Red Squirrel
Is there a way I can take a char array and replace every NN with NNN? I need this in a program I wrote a while back and I'm fixing it up because I found a bug in it and I'll need to turn every
into
. IIS does not like
, I noticed.
Basically I'm looking for something like the str_replace function in php.
Archived topic from Anythingforums, old topic ID:88, old post ID:822
replace NN with NNN
Posted: Sun Jun 27, 2004 5:05 am
by megaspaz
you could just create a function that loops through a string looking for the set of characters you want to replace and replace them. probably a lot quicker than asking on a forum.
Archived topic from Anythingforums, old topic ID:88, old post ID:1749
replace NN with NNN
Posted: Sun Jun 27, 2004 1:18 pm
by Red Squirrel
I tried that but it got complicated. If it's one character it's not so bad, but if there's more then one then things can complicated. In this case it's only one char
but the fact thta I'm replacing it with 2 will make things complicated since I can't just go
string[position] = '
'
string[position+1] = '
'
Since the second one would overwrite whatever data is there, so I would need to somehow take this data, store it somewhere else, then put it back after position+1..... quite complex and probably very resource intensive.
Archived topic from Anythingforums, old topic ID:88, old post ID:1837
replace NN with NNN
Posted: Sun Jun 27, 2004 1:57 pm
by megaspaz
Red Squirrel wrote: I tried that but it got complicated. If it's one character it's not so bad, but if there's more then one then things can complicated. In this case it's only one char
but the fact thta I'm replacing it with 2 will make things complicated since I can't just go
string[position] = '
'
string[position+1] = '
'
Since the second one would overwrite whatever data is there, so I would need to somehow take this data, store it somewhere else, then put it back after position+1..... quite complex and probably very resource intensive.
no but you can use a temporary string buffer to handle all the characters. i don't know how php works, so i don't know if you can make the string buffer dynamic in size or not, but while your checking the character of the original string, your copying the current character into a dynamically allocated string buffer array (whatever php uses) and when you come across a '
', you add the '
' to the buffer after copying the '
' into the buffer.
Archived topic from Anythingforums, old topic ID:88, old post ID:1844
replace NN with NNN
Posted: Sun Jun 27, 2004 2:24 pm
by Red Squirrel
hmm I think I know what you're saying. I could try that. That's the beauty of php though, you don't have to allowcate arrays, they are all unlimited. It's just $variable and it can hold from 1 character to the whole internet's content. But with C++ you have to allowcate it but I think if you use a char* it's sort of dynamic but it's still very limited compared to php. C++ vars used stack memory I believe while php probably uses every part of the memory it can find, including swap so the only limit is the server.
Archived topic from Anythingforums, old topic ID:88, old post ID:1855
replace NN with NNN
Posted: Sun Jun 27, 2004 2:31 pm
by megaspaz
Red Squirrel wrote: hmm I think I know what you're saying. I could try that. That's the beauty of php though, you don't have to allowcate arrays, they are all unlimited. It's just $variable and it can hold from 1 character to the whole internet's content. But with C++ you have to allowcate it but I think if you use a char* it's sort of dynamic but it's still very limited compared to php. C++ vars used stack memory I believe while php probably uses every part of the memory it can find, including swap so the only limit is the server.
actually with c++ if you use the STL's string container, you could do the same thing dynamically. you can even use syntactic sugar of the running total statement... ie. s1 = s1 + s2
Archived topic from Anythingforums, old topic ID:88, old post ID:1856
replace NN with NNN
Posted: Sun Jun 27, 2004 2:36 pm
by Red Squirrel
Yeah but in my case I need to use chars, since that's what the send and recv commands use. I think my best bet will be to just hard code a function in my program and make it speficly for replacing
with
. I just figured there would of been a function where I just plug everything in, but it does not seem like it.
Archived topic from Anythingforums, old topic ID:88, old post ID:1857
replace NN with NNN
Posted: Sun Jun 27, 2004 2:44 pm
by megaspaz
Red Squirrel wrote: Yeah but in my case I need to use chars, since that's what the send and recv commands use. I think my best bet will be to just hard code a function in my program and make it speficly for replacing
with
. I just figured there would of been a function where I just plug everything in, but it does not seem like it.
in the stl string container there's a method that will return a c-style string (char *). the stl string container can be initialized with a c-style string as well as return a c-style string. i can't remember off the top of my head, but i think the method is c_str -> return s1.c_str ();
Archived topic from Anythingforums, old topic ID:88, old post ID:1858
replace NN with NNN
Posted: Sun Jun 27, 2004 2:57 pm
by Red Squirrel
oh ok... do you have any links to a tutorial for the stl container stuff? Maybe it's something worth learning.
Archived topic from Anythingforums, old topic ID:88, old post ID:1860
replace NN with NNN
Posted: Sun Jun 27, 2004 3:34 pm
by megaspaz
http://www.google.com/search?hl=en&ie=ISO-...G=Google+Search
Archived topic from Anythingforums, old topic ID:88, old post ID:1868