WEB开发网
开发学院手机开发Symbian 开发 S60平台简体汉字处理浅谈 阅读

S60平台简体汉字处理浅谈

 2010-07-21 04:21:00 来源:WEB开发网   
核心提示:_LIT( KFileName, "privatexxxxxxxxaTextFile.txt" ); RFs FileServerSession; User::LeaveIfError(FileServerSession.Connect()); RFile file; if ( file.Repla

_LIT( KFileName, "privatexxxxxxxxaTextFile.txt" ); RFs FileServerSession; User::LeaveIfError(FileServerSession.Connect()); RFile file; if ( file.Replace(FileServerSession, KFileName, EFileWrite ) != KErrNone ) { return; } CleanupClosePushL( file ); _LIT8( KNonUnicodeString, "简体汉字串"); TPtrC8 point8( KNonUnicodeString ); 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 ); } TInt state=CCnvCharacterSetConverter::KStateDefault; HBufC* UnicodeString = HBufC::NewL( point8 ); TPtr16 point16 = UnicodeString->Des(); 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 =

上一页  1 2 3 4 5 6  下一页

Tags:平台 汉字

编辑录入:coldstar [复制链接] [打 印]
赞助商链接