replace NN with NNN

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

replace NN with NNN

Post 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
Honk if you love Jesus, text if you want to meet Him!
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

replace NN with NNN

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

replace NN with NNN

Post 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
Honk if you love Jesus, text if you want to meet Him!
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

replace NN with NNN

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

replace NN with NNN

Post 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
Honk if you love Jesus, text if you want to meet Him!
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

replace NN with NNN

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

replace NN with NNN

Post 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
Honk if you love Jesus, text if you want to meet Him!
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

replace NN with NNN

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

replace NN with NNN

Post 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
Honk if you love Jesus, text if you want to meet Him!
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

replace NN with NNN

Post 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
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
Locked