Substring replacement

  • Thread starter Michael McGarry
  • Start date
M

Michael McGarry

Hi,

Is there a standard C library routine that does substring replacement?

i.e. src: "mySpecialString" ---> dest: "myDullString"

Something like this
strsubrepl(src,dest,"Special", "Dull");??

Thanks for any help,

Michael
 
M

Michael Mair

Michael said:
Hi,

Is there a standard C library routine that does substring replacement?

i.e. src: "mySpecialString" ---> dest: "myDullString"

Something like this
strsubrepl(src,dest,"Special", "Dull");??

No.
Reasons: You can easily roll one yourself and may take advantage
of special structures this way.
The most recent thread about string replacement I can recall started at
<[email protected]>

Cheers
Michael
 
J

jagadeeshbp

Hi,
I think there is no direct call, as mentioned by others. But just
using strtok() - get the prefix, replace the rest of the string and
re-concatenate the prefix and the replaced string - the same can be
achieved.
 
M

Michael Mair

Hi,
I think there is no direct call, as mentioned by others. But just
using strtok() - get the prefix, replace the rest of the string and
re-concatenate the prefix and the replaced string - the same can be
achieved.

I do not think that strtok() is the right tool for the job as it
looks only for delimiter characters but not delimiter strings;
you still need something to match the rest of the string, so
you can just go with strstr().
strstr() definitely is a safe function which can be easily used,
quite in contrast to the somewhat obscure semantics of strtok().

Cheers
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top