3. TBuf转Tint型
// 15位数字 TInt iNum1(123456789009876); // 将缓存的内容设置为iNum1 iBuf.Num(iNum1); // 使用iBuf包含的内容创建TLex对象 // the 15 digit number TLex iLex(iBuf); // iNum1 TInt iNum2; //iNum2现在包含了15位数字 iLex.Val(iNum2);
4. Tint转TBuf型
TBuf<10>tmp; Tint ti=190; Tmp.AppendNum(ti);
5. TBuf转TDateTime型
将长的TBuf截成小段,分别是年月日时分秒,通过下面TBuf转TInt ,再分别把转换成TInt的年月日取出,通过TDateTime的setYear(),setMonth()等方法将时间set进TDateTime,
6. 其他转换
/* 数据类型转换*/
//TBuf 转换为 TPtrC16
TBuf<32> tText(_L("2004/11/05 05:44:00"));
TPtrC16 tPtrSecond=tText.Mid(17,2);
//TPtrC16 转换为 TBufC16
TPtrC16 tPtrSecond=tText.Mid(17,2);
TBufC16<10> bufcs(tPtrSecond);
//TBufC16 转换为 TPtr16
TBufC16<10> bufcs(tPtrSecond);
TPtr16 f=bufcs.Des();
//TPtr16 转换为 TBuf
TBuf<10> bufSecond;
bufSecond.Copy(f);
//TBuf 转换为 TPtr16
TBuf<10> bufSecond(_L("abc"));
TPtr16 f;
f.Copy(bufSecond);
//TBuf 转换为 TInt
TInt aSecond;
TLex iLexS(bufSecond);
iLexS.Val(aSecond);
//TInt 转换为 TBuf
TBuf<32> tbuf;
TInt i=200;
tbuf.Num(i); 7.串转换成数字
TBuf16<20> buf(_L( "123" ) );
TLex lex( buf );
TInt iNum;
lex.Val( iNum );
8.数字转换成串
TBuf16<20> buf; TInt iNum = 20; buf.Format( _L( "%d" ) , iNum );
9.将symbian串转换成char串
char* p = NULL;
TBuf8<20> buf( _L( "aaaaa" ) );
p = (char *)buf.Ptr(); 10.UTF-8转换成UNICODE
CnvUtfConverter::ConvertToUnicodeFromUtf8( iBuf16 , iBuf8 );
11.UNICODE转换成UTF-8
CnvUtfConverter::ConvertFromUnicodeToUtf8( iBuf8 , iBuf16 );
12.将char串转换成symbian串
char* cc = "aaaa";
TPtrC8 a;
a.Set( (const TUint8*)cc , strlen(cc) );
13.Symbian中TBuf初始化汉字为乱码的解决方法
对于程序中添加提示信息,一般会采用下面的方法实现:
_LIT(KMessage, "database created.");
TBuf<22> str(KMessage);
CEikonEnv::Static()->InfoWinL(_L("search: "), str); 但对于汉字提示信息,采用这种方法则会出现乱码:
_LIT(KMessage, "数据库创建成功");
TBuf<22> str(KMessage);
CEikonEnv::Static()->InfoWinL(_L("search: "), str); //显示乱码 可以采用下面的方法,使之能够正常显示汉字:
_LIT8(KMessage,"数据库创建成功");
TBufC8<22> str8(KMessage);
TBuf<50> str16;
CnvUtfConverter::ConvertToUnicodeFromUtf8(str16,str8);
CEikonEnv::Static()->InfoWinL(_L("search: "), str16); //正常显示汉字
注 意:使用CnvUtfConverter时,需要包含头文件:UTF.H ;库:charconv.lib
Bookmark
Email this
Hits: 1032
Comments (0)

Write comment



