Find and replace

This is a discussion on Find and replace within the C++ Programming forums, part of the General Programming Boards category; I wrote this in javascript already, but ide like to put it in my program also, so how would i ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    8

    Find and replace

    I wrote this in javascript already, but ide like to put it in my program also, so how would i do this in c++. Find a certain group of characters and replace it with another.
    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <SCRIPT LANGUAGE="JavaScript">
    function replaceChars(entry) {
    out = "."; // replace this
    add = "/n"; // with this
    temp = "" + entry; // temporary holder
    
    while (temp.indexOf(out)>-1) {
    pos= temp.indexOf(out);
    temp = "" + (temp.substring(0, pos) + add + 
    temp.substring((pos + out.length), temp.length));
    }
    document.subform.text.value = temp;
    }
    </script>
    </head>
    
    <body>
    <center>
    <form name="subform">
    
        <textarea name="text" cols="85" rows="40" wrap="VIRTUAL">Enter Text Here</textarea>
        <br>
    <input type=button name=action value="Finish" onClick="replaceChars(document.subform.text.value);">
    </form>
    </center>
    </body>
    </html>

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    The STL string class has find() and replace() methods.

    gg

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. Find and replace within a string?
    By clancyPC in forum C Programming
    Replies: 3
    Last Post: 03-20-2009, 07:28 AM
  3. please help!...find and replace
    By amy589 in forum C++ Programming
    Replies: 26
    Last Post: 10-13-2006, 06:42 PM
  4. Find and Replace Text Function
    By mart_man00 in forum C Programming
    Replies: 45
    Last Post: 03-13-2003, 09:21 PM
  5. find and replace command?
    By p0wp0wpanda in forum C Programming
    Replies: 2
    Last Post: 05-24-2002, 11:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21