Can someone point me to some nice clean search and replace code?
-
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?
-
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?
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++
-
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++
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!
-
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!
-
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++
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?
-
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
Yes, only an MDI parent window (
IsMdiParent
property set totrue
) can have MDI children. -- LuisR
Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!
-
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?
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++