Results 1 to 4 of 4

Thread: Replace part of text with other text

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    115
    Ok, I have two RichText-boxes, and when pressing a button I want to replace a certain part of the first RichTextBox with the content in the second. How do I do this?

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Mike (Parksie) wrote this example for me:


    Code:
    #include <String>
    using namespace std;
    
    bool StringFind(String sSearchIn, String sSearchFor, uint &nPos) {
    
    		uint nTemp = sSearchIn.find(sSearchFor);
    		If(nTemp < sSearchIn.length()) {
    			nPos = nTemp;
    			Return True;
    		}
    
    		Return False;
    	}
    
    bool Replace(String &sLine, String sReplaceWhat, String sReplaceWith) {
    
    		uint nPos = 0;
    		uint i = 0;
    		While (StringFind(sLine, sReplaceWhat, nPos)) {
    			If(i > 100) break; // Something's gone wrong (sReplaceWhat ~= sReplaceWith)
    			sLine = sLine.replace(nPos, sReplaceWhat.length(), sReplaceWith);
    			i++;
    		}
    		If(i) Return True; Return False;
    	}
    Have fun, and don't thank me, it was parksie's
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Bugger...looks like VB-W just destroyed my capitalisation
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I think that's Geoff's VbWorld browser then
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width