how to change one BYTE in CString
-
Hi, all
CString cstr = "abcd"; LPTSTR p = cstr.GetBuffer(); p[2] = 'r'; // cstr is abcd, but not is abrd
I want to change 'c' to 'r' in cstr. How to do?hanlei0000000009 wrote:
// cstr is abcd, but not is abrd
CString cstr = "abcd"; cstr.SetAt( 2,'r');
hanlei0000000009 wrote:
I want to change 'c' to 'r' in cstr.
But your purpose is to replace the c with r, you can use the Replace function..
CString cstr = "abcd"; cstr.Replace( 'c','r');
nave [OpenedFileFinder]
modified on Thursday, March 27, 2008 11:37 PM
-
Hi, all
CString cstr = "abcd"; LPTSTR p = cstr.GetBuffer(); p[2] = 'r'; // cstr is abcd, but not is abrd
I want to change 'c' to 'r' in cstr. How to do?You rarely need to use GetBuffer(). The CString class has most functions you need, including SetAt()...
CString cstr = _T("abcd");
cstr.SetAt(2, _T('r'));If you insist on using GetBuffer(), remember: "If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer ..."
CString cstr = _T("abcd");
LPTSTR p = cstr.GetBuffer();
p[2] = _T('r');
cstr.ReleaseBuffer();Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
You rarely need to use GetBuffer(). The CString class has most functions you need, including SetAt()...
CString cstr = _T("abcd");
cstr.SetAt(2, _T('r'));If you insist on using GetBuffer(), remember: "If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer ..."
CString cstr = _T("abcd");
LPTSTR p = cstr.GetBuffer();
p[2] = _T('r');
cstr.ReleaseBuffer();Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
:laugh:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
:laugh:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeSomeone said to me that in the next version of MFC, this function would be renamed to
GetBufferIReallyKnowWhatImDoing()
:laugh:Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
:laugh:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarkei will take ReleaseBuffer revenge!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/codeProject$$>
-
Someone said to me that in the next version of MFC, this function would be renamed to
GetBufferIReallyKnowWhatImDoing()
:laugh:Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
..and they will also add the method
PlzGetBuf
, always throwing by design. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
..and they will also add the method
PlzGetBuf
, always throwing by design. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeCPallini wrote:
..and they will also add the method PlzGetBuf, always throwing by design.
One more
GiveMeBufOtherwiseOsama
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/codeProject$$>
-
..and they will also add the method
PlzGetBuf
, always throwing by design. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeCPallini wrote:
PlzGetBuf
Does it take a boolean parameter too?
PlzGetBuf(BOOL bUrgent)
:rolleyes:Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
CPallini wrote:
PlzGetBuf
Does it take a boolean parameter too?
PlzGetBuf(BOOL bUrgent)
:rolleyes:Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
Rajesh R Subramanian wrote:
Does it take a boolean parameter too? PlzGetBuf(BOOL bUrgent)
Actually it does, however it is optional:
PXSTR PlzGetBuf(BOOL bUrgent = TRUE);
:-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Rajesh R Subramanian wrote:
Does it take a boolean parameter too? PlzGetBuf(BOOL bUrgent)
Actually it does, however it is optional:
PXSTR PlzGetBuf(BOOL bUrgent = TRUE);
:-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke:laugh:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP