Click to See Complete Forum and Search --> : Replace part of text with other text
CreoN
Mar 5th, 2001, 01:45 PM
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?
Jop
Mar 5th, 2001, 05:32 PM
Mike (Parksie) wrote this example for me:
#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 :D
parksie
Mar 6th, 2001, 12:07 PM
Bugger...looks like VB-W just destroyed my capitalisation :rolleyes:
Jop
Mar 6th, 2001, 05:22 PM
I think that's Geoff's VbWorld browser then ;)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.