日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[转]symbian基本类型转换

發布時間:2025/7/14 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [转]symbian基本类型转换 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
TDesC是所有字符類的祖先


標準C語言
Symbian OS

讓一個字符串進入2進制代碼
Static char hellorom[]=”hello”
_LIT(khellorom,”hello”)

在棧中獲得字符串的指針
Const char* helloptr=hellorom
TPtrC helloptr=khellorom

獲得在棧中字符串的指針
Char hellostack[sizeof(hellorom)];

Strcpy(hellostack,hellorom);
TBufC<5> hellostack=khellorom;

獲得在堆中字符串的指針
Char* helloheap=

(char *)malloc(sizeof(hellorom));

strcpy(helloheap,hellorom);
HBufC* helloheap=

Khellorom.AllocLC();


a)TPtrC相當于不變的字符串常量.

b)TPtr相當與String類型。Tbuf相當于char[]。前者與后者的唯一區別是,后者需要指定分配的棧空間大小。

C)HBufC* 與char*類似。分配的是堆上的空間。

HBufC* textResource;

//兩種字符串附值方法

textResource = StringLoader::LoadLC( R_HEWP_TIME_FORMAT_ERROR );

textResource =iEikonEnv->AllocReadResourceL(R_EXAMPLE_TEXT_HELLO);

TBuf<32> timeAsText;

timeAsText = *textResource;

/* 數據類型轉換*/


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);

1.串轉換成數字
?? TBuf16<20> buf(_L( "123" ) );
????TLex lex( buf );
????TInt iNum;
????lex.Val( iNum );
2.數字轉換成串
?? TBuf16<20> buf;
?? TInt iNum = 20;
?? buf.Format( _L( "%d" ) , iNum??);
3.將symbian串轉換成char串
????char* p = NULL;
????TBuf8<20> buf( _L( "aaaaa" ) );
????p = (char *)buf.Ptr();

4.UTF-8轉換成UNICODE
????CnvUtfConverter::ConvertToUnicodeFromUtf8( iBuf16 , iBuf8 );
5.UNICODE轉換成UTF-8
????CnvUtfConverter::ConvertFromUnicodeToUtf8( iBuf8 , iBuf16 );


6.將char串轉換成symbian串
????char* cc = "aaaa";
????TPtrC8 a;
????a.Set( (const TUint8*)cc , strlen(cc) );

7、將TPtrc8與TPtrc16之間轉化

// Get a iBuf8 from a iBuf16 (data are not modified)
TPtrC8 ptr8(reinterpret_cast<const TUint8*>(iBuf16.Ptr()),(iBuf16.Size()*2));
iBuf8=ptr8;

// Get a iBuf16 from a iBuf8 (data are not modified)
TPtrC16 ptr16(reinterpret_cast<const TUint16*>(iBuf8.Ptr()),(iBuf8.Size()/2));
iBuf16=ptr16;


The second one takes each character and convert it to the other format. The 16-bit to 8-bit conversion may not always succeed in this case:

Code:

// Get a iBuf8 from a iBuf16 (data are modified)
CnvUtfConverter::ConvertFromUnicodeToUtf8(iBuf8,iBuf16);

// Get a iBuf16 from a iBuf8 (data are modified)
CnvUtfConverter::ConvertToUnicodeFromUtf8(iBuf16,iBuf8);


This second method requires to include the utf.h header and to link against charconv.lib.

/*memset?? memcpy?? strcpy */

memset主要應用是初始化某個內存空間。用來對一段內存空間全部設置為某個字符。
memcpy是用于COPY源空間的數據到目的空間中,用來做內存拷貝可以拿它拷貝任何數據類型的對象。
strcpy只能拷貝字符串了,它遇到'"0'就結束拷貝。



strcpy
原型:extern char *strcpy(char *dest,char *src);
用法:#include <string.h>
功能:把src所指由NULL結束的字符串復制到dest所指的數組中。
說明:src和dest所指內存區域不可以重疊且dest必須有足夠的空間來容納src的字符串。
?????? 返回指向dest的指針。
??????
memcpy
原型:extern void *memcpy(void *dest, void *src, unsigned int count);
用法:#include <string.h>
功能:由src所指內存區域復制count個字節到dest所指內存區域。
說明:src和dest所指內存區域不能重疊,函數返回指向dest的指針。

memset
原型:extern void *memset(void *buffer, int c, int count);
用法:#include <string.h>
功能:把buffer所指內存區域的前count個字節設置成字符c。

說明:返回指向buffer的指針。

?

?

?原文:http://www.cppblog.com/gtwdaizi/articles/47764.html

轉載于:https://www.cnblogs.com/felixYeou/archive/2008/09/05/1285203.html

總結

以上是生活随笔為你收集整理的[转]symbian基本类型转换的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。