Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Can someone point me to some nice clean search and replace code?

Can someone point me to some nice clean search and replace code?

Scheduled Pinned Locked Moved C#
csharphelpquestionworkspace
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ArchKaine
    wrote on last edited by
    #1

    To be more specific, I need the code for a text editor / RTF editor that I'm working on and I'm more than a little bit new at this coding thing, so I'm not too certain as to where to look for good clean snippets that provide the functionality that I need. I'd try to write the code myself, but I have at the moment a lack of two things: Time, since I've joined the Naval Reserve, and am studying a lot - and appropriate knowledge, since C# is essentially my first programming language since the "good ol' days" of Level 2 BASIC (anyone out there remember that one?). Anyhoo, any help than you can all provide would be greatly appreciated. Specific functionality that I'm trying to implement, but haven't found a clue to: Global search and replace among all documents in an MDI environment. Specific search and replace on a per-document basis. Undo/redo functionality for both of the previous cases would also be good. Thanks in advance for any help, and if you provide code, you'll be appropriately credited :) B Turner Some say that ignorance is bliss... Blissful, aren't they?

    C 1 Reply Last reply
    0
    • A ArchKaine

      To be more specific, I need the code for a text editor / RTF editor that I'm working on and I'm more than a little bit new at this coding thing, so I'm not too certain as to where to look for good clean snippets that provide the functionality that I need. I'd try to write the code myself, but I have at the moment a lack of two things: Time, since I've joined the Naval Reserve, and am studying a lot - and appropriate knowledge, since C# is essentially my first programming language since the "good ol' days" of Level 2 BASIC (anyone out there remember that one?). Anyhoo, any help than you can all provide would be greatly appreciated. Specific functionality that I'm trying to implement, but haven't found a clue to: Global search and replace among all documents in an MDI environment. Specific search and replace on a per-document basis. Undo/redo functionality for both of the previous cases would also be good. Thanks in advance for any help, and if you provide code, you'll be appropriately credited :) B Turner Some say that ignorance is bliss... Blissful, aren't they?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The string class has search and replace methods, that is, if your text is one big string, you can use the replace method to do search and replace, or you can use other methods to find the strings without replacing. I'm not sure how to iterate through all documents in an MDI app, but I'm sure google can help here. The easiest way to do undo is to make a copy of your document in memory before each action and push them on to a stack. If you want to only store the differences between documents to save memory ( no need with text, I would think ), then you need to get a little more complex. Christian Graus - Microsoft MVP - C++

      L A 2 Replies Last reply
      0
      • C Christian Graus

        The string class has search and replace methods, that is, if your text is one big string, you can use the replace method to do search and replace, or you can use other methods to find the strings without replacing. I'm not sure how to iterate through all documents in an MDI app, but I'm sure google can help here. The easiest way to do undo is to make a copy of your document in memory before each action and push them on to a stack. If you want to only store the differences between documents to save memory ( no need with text, I would think ), then you need to get a little more complex. Christian Graus - Microsoft MVP - C++

        L Offline
        L Offline
        Luis Alonso Ramos
        wrote on last edited by
        #3

        Christian Graus wrote: I'm not sure how to iterate through all documents in an MDI app,

        foreach(Form form in this.MdiChildren)
        {
            // See if it's a document form
            TextDocumentForm textForm = form as TextDocumentForm;
         
            if(textForm != null)
            {
                // Do whatever with the form
            }
        }
        

        Now you know! ;P -- LuisR


        Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

        A 1 Reply Last reply
        0
        • L Luis Alonso Ramos

          Christian Graus wrote: I'm not sure how to iterate through all documents in an MDI app,

          foreach(Form form in this.MdiChildren)
          {
              // See if it's a document form
              TextDocumentForm textForm = form as TextDocumentForm;
           
              if(textForm != null)
              {
                  // Do whatever with the form
              }
          }
          

          Now you know! ;P -- LuisR


          Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

          A Offline
          A Offline
          ArchKaine
          wrote on last edited by
          #4

          I would place this code into the MdiParent, right? Something tells me that that's the only logical place to put it, but I wanted to be sure. Thanks again :) Brian Turner

          L 1 Reply Last reply
          0
          • C Christian Graus

            The string class has search and replace methods, that is, if your text is one big string, you can use the replace method to do search and replace, or you can use other methods to find the strings without replacing. I'm not sure how to iterate through all documents in an MDI app, but I'm sure google can help here. The easiest way to do undo is to make a copy of your document in memory before each action and push them on to a stack. If you want to only store the differences between documents to save memory ( no need with text, I would think ), then you need to get a little more complex. Christian Graus - Microsoft MVP - C++

            A Offline
            A Offline
            ArchKaine
            wrote on last edited by
            #5

            I think that what I need is a code snippet, know of any good places to get that? Reason being is I learn better by having something to emulate. I'm still learning how to implement various classes. I'll post the code that I have so far, when I am able, so that you can all have something to chuckle at :) Thanks for the help :) Brian Turner Some say that ignorance is bliss... Blissful, aren't they?

            C 1 Reply Last reply
            0
            • A ArchKaine

              I would place this code into the MdiParent, right? Something tells me that that's the only logical place to put it, but I wanted to be sure. Thanks again :) Brian Turner

              L Offline
              L Offline
              Luis Alonso Ramos
              wrote on last edited by
              #6

              Yes, only an MDI parent window (IsMdiParent property set to true) can have MDI children. -- LuisR


              Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

              1 Reply Last reply
              0
              • A ArchKaine

                I think that what I need is a code snippet, know of any good places to get that? Reason being is I learn better by having something to emulate. I'm still learning how to implement various classes. I'll post the code that I have so far, when I am able, so that you can all have something to chuckle at :) Thanks for the help :) Brian Turner Some say that ignorance is bliss... Blissful, aren't they?

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                string theDocument = LoadString(); // This method does not exist, you need to get the text of the document theDocument.Replace("oldstring", "newString"); Christian Graus - Microsoft MVP - C++

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups