RBuf8 to char * in Symbian C ++
I am loading a text string from a web service in RBuf8 using this kind of code (it works ..)
void CMyApp::BodyReceivedL( const TDesC8& data ) {
int newLength = iTextBuffer.Length() + data.Length();
if (iTextBuffer.MaxLength() < newLength)
{
iTextBuffer.ReAllocL(newLength);
}
iTextBuffer.Append(data);
}
I want to convert RBuf8 to a char * string which I can display on a label or whatever .. or for debugging purposes, display in
RDebug::Printf("downloading text %S", charstring);
change for clarity.
My transform function looks like this.
void CMyApp :: DownloadCompleteL () {{RBuf16 buf; buf.CreateL (iTextBuffer.Length ()); buf.Copy (iTextBuffer);
RDebug::Printf("downloaded text %S", buf);
iTextBuffer.SetLength(0);
iTextBuffer.ReAlloc(0);
}
But it still wrecks. I am using S60 3rd Edition FP2 v1.1
source to share
What you might need is something like:
RDebug::Print( _L( "downloaded text %S" ), &buf );
This tutorial can help you.
source to share
void RBuf16 :: Copy (const TDesC8 &) will take an 8 bit descriptor and convert it to a 16 bit descriptor.
You should be able to display any 16-bit descriptor on the screen. If it doesn't work, please post the specific API you are using.
When the API can be used with undefined parameters (for example, void RDebug :: Printf (const char *, ...)),% S is used for a "pointer to a 16-bit descriptor". Notice the uppercase% S.
source to share
Thank you,% S is a helpful reminder.
However, this doesn't work. My transform function looks like this.
void CMyApp::DownloadCompleteL() {
{
RBuf16 buf;
buf.CreateL(iTextBuffer.Length());
buf.Copy(iTextBuffer);
RDebug::Printf("downloaded text %S", buf);
iTextBuffer.SetLength(0);
iTextBuffer.ReAlloc(0);
}
But it still wrecks. I am using S60 3rd Edition FP2 v1.1
source to share