Thread: Find and replace within a string?

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    40

    Find and replace within a string?

    Hi,
    Is there a STL function that lets me pass a full string, a substring to find and a substring to replace it with?
    I will illustrate with an example:
    I have a string like this: PCGI1.BATCH.CTL.OD.SEW4137.D
    In that string I want to find the substring "CTL" and replace it with the substring "CDR"
    Is there an existing function to do this in the STL that anyone knows of, and if not can anyone suggest a solution; I seem to be suffering from brain deadedness (as proven by the use of the word deadedness) and just cant see a solution.
    Thanks

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    STL is C++. Why you are asking question on C-forum?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    40
    I thought there was an STL in C as well? If not then just replace STL with standard library of functions or whatever it is you want to call it; fred, george, betty its entirely up to you.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    40
    Its alright, my brain has woken up again, all done.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to find and replace a string in a file
    By salzouby in forum C Programming
    Replies: 13
    Last Post: 09-14-2010, 08:55 AM
  2. String replace
    By guitarist809 in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2008, 03:53 PM
  3. Errors with program to replace string with another
    By Dan17 in forum C Programming
    Replies: 3
    Last Post: 09-14-2006, 10:15 AM
  4. Replies: 5
    Last Post: 05-25-2004, 04:36 PM
  5. Find and Replace Text Function
    By mart_man00 in forum C Programming
    Replies: 45
    Last Post: 03-13-2003, 10:21 PM