Symbian C 各種型別之間的轉換!!

2021-04-13 21:30:26 字數 3572 閱讀 8871

1. ttime轉tbuf型

tbuf<32> thetime;//儲存轉換後的時間

ttime tt;

tt.hometime();

_lit(ktimeformat,"%y%m%d%1-%2-%3 %h:%t:%s");//格式為:2006-03-04 12:12:12

tt.formatl(thetime,ktimeformat);

2. tdatetime轉tbuf型

ttime currenttime;//宣告乙個ttime型別

currenttime.hometime();//設定ttime為當前時間

tdatetime tdt=currenttime.datetime();//ttime   --->   tdatetime

tbuf<32> tmp;//儲存轉換完的buf

_lit(gang,"-");//宣告乙個橫線分隔年月日,同樣可宣告冒號分隔小時分秒

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;

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

/*memset    memcpy    strcpy */

memset主要應用是初始化某個記憶體空間。用來對一段記憶體空間全部設定為某個字元。

memcpy是用於copy源空間的資料到目的空間中,用來做記憶體拷貝可以拿它拷貝任何資料型別的物件。

strcpy只能拷貝字串了,它遇到'/0'就結束拷貝。

s60的資料型別轉換(巨有用)

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

再加一點:

tdesc8 & buf ;

tuint8    * pdata ;

pdata = buf.ptr() ;

如果,怕pdata破壞的話,可以

tbuf8<1024> tmp_buf ;

tmp_buf.copy(buf) ;

pdata = tmp_buf.ptr() ;

這樣就可以保護一下buf的資料了,尤其是如果這個buf是socket的接收的資料是接收函式自己分配的時候。

strcpy

原型:extern char *strcpy(char *dest,char *src);

用法:#include

功能:把src所指由null結束的字串複製到dest所指的陣列中。

說明:src和dest所指記憶體區域不可以重疊且dest必須有足夠的空間來容納src的字串。

返回指向dest的指標。

memcpy

原型:extern void *memcpy(void *dest, void *src, unsigned int count);

用法:#include

功能:由src所指記憶體區域複製count個位元組到dest所指記憶體區域。

說明:src和dest所指記憶體區域不能重疊,函式返回指向dest的指標。

memset

原型:extern void *memset(void *buffer, int c, int count);

用法:#include

功能:把buffer所指記憶體區域的前count個位元組設定成字元c。

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

1. ttime轉tbuf型tbuf<32> thetime;//儲存轉換後的時間

ttime tt; tt.hometime();

_lit(ktimeformat,"%y%m%d%1-%2-%3 %h:%t:%s");//格式為:2006-03-04 12:12:12

tt.formatl(thetime,ktimeformat);

Symbian C 各種型別之間的轉換

1.ttime轉tbuf型 tbuf 32 thetime 儲存轉換後的時間 ttime tt tt.hometime lit ktimeformat,y m d 1 2 3 h t s 格式為 2006 03 04 12 12 12 tt.formatl thetime,ktimeformat 2...

SymbianC 各種型別之間的轉換

ttime轉tbuf型 tbuf 32 thetime 儲存轉換後的時間 ttime tt tt.hometime lit ktimeformat,y m d 1 2 3 h t s 格式為 2006 03 04 12 12 12 tt.formatl thetime,ktimeformat 3.t...

SymbianC 各種型別之間的轉換!! 整理

1.ttime轉tbuf型 tbuf 32 thetime 儲存轉換後的時間 ttime tt tt.hometime lit ktimeformat,y m d 1 2 3 h t s 格式為 2006 03 04 12 12 12 tt.formatl thetime,ktimeformat 2...