1. Use Copy
_ LIT8 (KTestStr, "This is a string ");
TBufC8 <50> buf (KTestStr );
TBuf <100> newBuf;
NewBuf. Copy (buf );
TBuf8 <50> newBuf1;
NewBuf1.Copy (newBuf );
2. Use the CCnvCharacterSetConverter class
_ LIT8 (KTestStr, "This is a String" n ");
TBufC8 <50> buf (KTestStr );
CCnvCharacterSetConverter * conv = CCnvCharacterSetConverter: NewL ();
CleanupStack: PushL (conv );
RFs fs;
User: LeaveIfError (fs. Connect ());
If (conv-> PrepareToConvertToOrFromL (KCharacterSetIdentifierAscii, fs )! = CCnvCharacterSetConverter: EAvailable)
{
User: Leave (KErrNotSupported );
}
HBufC * str = HBufC: NewL (buf. Length ());
CleanupStack: PushL (str );
TPtr = str-> Des ();
TInt state = CCnvCharacterSetConverter: KStateDefault;
If (conv-> ConvertToUnicode (ptr, buf, state) = CCnvCharacterSetConverter: EErrorIllFormedInput)
{
User: Leave (KErrArgument );
}
Fs. Close ();
Console-> Write (ptr );
CleanupStack: PopAndDestroy (2); // str, conv