|
-
April 14th, 1999, 08:23 AM
#1
Playing with CString and LPSTR, PLEASE HELP !!
Hi,
I'm trying to do a "replace" function that goes fast, my replace function is:
ReplaceString(CString &Text,int iBegin,int iEnd,CString &NewString)
And puts the "NewString" in the string "Text", deleting what is between iBegin and iEnd, for example:
Text = "aabbcccc"
NewString = "d"
ReplaceString(Text,2,3,NewString)
Make:
Text = "aadccc"
The problem is the case:
Text = "aabbc"
NewText = "defg"
ReplaceString(Text,3,4,NewString)
Gives me an error when tries to destroy the CString !, Here is the piece of code that I use for that case:
iResize = iNewSubStringLength-iOldSubStringLength;
pText = Text.GetBuffer(iTextLength+iResize); // +1?
pNewString = NewString.GetBuffer(0);
int iDst = iBegin+iOldSubStringLength;
int iSrc = iDst + iResize;
memmove(pText+iSrc,pText+iDst,sizeof(_T(' '))*iResize);
_tcsncpy(pText+iBegin,pNewString,iNewSubStringLength);
//memcpy(pText+iBegin,pNewString,iNewSubStringLength);
Text.ReleaseBuffer(iTextLength+iResize);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|