TDesC8与TDesC16之间的互转 ---转杨芹勍的博客

1、使用Copy

_LIT8(KTestStr, "This is a string"); TBufC8<50> buf(KTestStr); TBuf<100> newBuf; newBuf.Copy(buf); TBuf8<50> newBuf1; newBuf1.Copy(newBuf);

 

2:使用CCnvCharacterSetConverter

_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 ptr = 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

你可能感兴趣的:(String,user)