• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 2, 文章 - 73, 評論 - 60, 引用 - 0
            數據加載中……

            [S60]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的指針。

            posted on 2008-04-21 21:17 郭天文 閱讀(2440) 評論(0)  編輯 收藏 引用 所屬分類: S60

            久久婷婷激情综合色综合俺也去| 狠狠色婷婷久久一区二区三区| 久久精品无码一区二区三区免费 | 久久99精品国产自在现线小黄鸭 | 久久婷婷五月综合97色一本一本 | 三级三级久久三级久久 | 久久se精品一区精品二区| 色综合合久久天天综合绕视看| 精品久久久久久无码中文野结衣| 久久精品18| 久久99国产综合精品| 久久久久久一区国产精品| 久久久久人妻一区二区三区vr | 久久久www免费人成精品| 久久精品国产亚洲精品2020| 国产亚州精品女人久久久久久 | 久久国产一片免费观看| 日产精品久久久久久久性色| 国产精品激情综合久久| 欧美喷潮久久久XXXXx| 蜜桃麻豆www久久国产精品| 久久福利青草精品资源站| 亚洲综合伊人久久大杳蕉| 久久久久国产亚洲AV麻豆| 狠狠狠色丁香婷婷综合久久五月| 久久久黄色大片| 一级a性色生活片久久无少妇一级婬片免费放 | 久久精品男人影院| 婷婷综合久久中文字幕蜜桃三电影| 久久国产精品二国产精品| 亚洲国产精品一区二区久久| 久久ZYZ资源站无码中文动漫 | 色婷婷综合久久久久中文| 亚洲国产视频久久| 香蕉久久AⅤ一区二区三区| 国产99久久久久久免费看| 欧美久久综合性欧美| 国产成人久久久精品二区三区| 国产午夜精品理论片久久影视 | 国产精品久久99| 久久久久久久99精品免费观看|