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

相关文章:

  • 2021-11-02
  • 2021-12-25
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
  • 2021-12-24
猜你喜欢
  • 2021-11-25
  • 2021-06-25
  • 2021-05-15
  • 2021-06-30
  • 2021-10-23
  • 2021-11-13
  • 2022-12-23
相关资源
相似解决方案