Symbian S60 平台简体汉字处理浅谈
2010-02-25 04:37:00 来源:WEB开发网if( CCnvCharacterSetConverter::EErrorIllFormedInput ==
characterSetConverter->ConvertToUnicode(point16, point8, state ) )
{
CleanupStack::PopAndDestroy();
User::Leave(KErrArgument);
}
RFileWriteStream StreamWriteToFile( file );
CleanupClosePushL( StreamWriteToFile );
StreamWriteToFile << *UnicodeString;
CleanupStack::PopAndDestroy(4);//file StreamWriteToFile characterSetConverter UnicodeString
FileServerSession.Close();
直接读取的方法与UTF-8编码简体汉字串读写文件的读文件操作相同。
2).将字串直接写入文件后再读取转换:
直接写文件的方法与UTF-8编码简体汉字串读写文件的写文件操作相同。
//读取后转换
RFs FileServerSession;
RFile file;
User::LeaveIfError(FileServerSession.Connect());
CleanupClosePushL(FileServerSession);
User::LeaveIfError(file.Open(FileServerSession,KHelloFileName, EFileStreamText));
CleanupClosePushL(file);
RFileReadStream StreamReadFromFile(file);
CleanupClosePushL(StreamReadFromFile);
HBufC* StreamData = HBufC::NewLC(StreamReadFromFile, 32);
HBufC8* StreamData8 = HBufC8::NewLC( StreamData->Length() );
StreamData8->Des().Copy(*StreamData);
TPtrC8 point8( *StreamData8 );
CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
if( converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGbk,
iEikonEnv->FsSession()) == CCnvCharacterSetConverter::EAvailable )
{
}
else if ( characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGb2312,
iEikonEnv->FsSession())!= CCnvCharacterSetConverter::EAvailable )
{
CleanupStack::PopAndDestroy();
User::Leave( KErrNotSupported );
更多精彩
赞助商链接