Symbian basic data type conversion and collection (3)

Source: Internet
Author: User

1. tTime to tbuf type

Tbuf <32> thetime; // stores the converted time
TTime tt;
TT. hometime ();
_ Partition (ktimeformat, "% Y % m % d % 1-% 2-% 3% H: % T: % s"); // format: 12:12:12
TT. formatl (thetime, ktimeformat); // formatl () will format the time in the form of a ktimeformat string and assign the value to thetime

2. tdatetime to tbuf type

TTime currenttime; // declare a tTime type
Currenttime. hometime (); // set tTime to the current time
Tdatetime TDT = currenttime. datetime (); // tTime ---> tdatetime
Tbuf <32> TMP; // store the converted Buf
TMP. appendnum (TDT. Year (); // use the appendnum () method to add a tint to tbuf.
_ Blank (gang, "-"); // declare a horizontal line to separate year, month, and day. You can also declare a colon to separate hours, minutes, and seconds.
TMP. append (gang );
TMP. appendnum (TDT. Month ());
TMP. append (gang );
TMP. appendnum (TDT. Day ());............ The time and second conversion is the same as above.

3. tbuf to tint type

// 15 digits
Tint inum1 (123456789009876 );
// Set the cached content to inum1
Ibuf. Num (inum1 );
// Use the ibuf content to create a tlex object
// The 15 digit number
Tlex Ilex (ibuf );
// Inum1
Tint inum2;
// Inum2 now contains 15 digits
Ilex. Val (inum2 );

4. tint to tbuf type

Tbuf <10> TMP;
Tint Ti = 190;
TMP. appendnum (Ti );

5. tbuf to tdatetime type

Cut a long tbuf into a short segment, namely, year, month, day, minute, and second. Use the following tbuf to convert it to tint, and then extract the year, month, and day converted to tint respectively. Use setyear () and setmonth () of tdatetime () set the time To tdatetime.

6. Other Conversions

Tbuf to tptrc16

Tbuf <32> ttext (_ L ("05:44:00 "));
Tptrc16 tptrsecond = ttext. mid (17,2 );

Tptrc16 to tbufc16

Tptrc16 tptrsecond = ttext. mid (17,2 );
Tbufc16 <10> bufcs (tptrsecond );

Tbufc16 to tptr16

Tbufc16 <10> bufcs (tptrsecond );
Tptr16 F = bufcs. Des ();

Tptr16 to tbuf

Tbuf <10> bufsecond;
Bufsecond. Copy (f );

Tbuf to tptr16

Tbuf <10> bufsecond (_ L ("ABC "));
Tptr16 F;
F. Copy (bufsecond );

Tbuf to tint

Tint Asecond;
Tlex ilexs (bufsecond );
Ilexs. Val (Asecond );

Tint to tbuf

Tbuf <32> tbuf;
Tint I = 200;
Tbuf. Num (I );

The main application of memset is to initialize a memory space. It is used to set all the memory space to a certain character.
Memcpy is used to copy data from the source space to the target space. It is used for memory copying to copy any data type objects.
Strcpy can only copy strings. If it encounters '/0', the copy ends.

Below is the data type conversion of s60 (very useful)

1. String Conversion to numbers

Tbuf16 <20> Buf (_ L ("123 "));
Tlex Lex (BUF );
Tint inum;
Lex. Val (inum );

2. convert numbers into strings

Tbuf16 <20> Buf;
Tint inum = 20;
Buf. Format (_ L ("% d"), inum );

3. convert a Symbian string to a char string

Char * P = NULL;
Tbuf8 <20> Buf (_ L ("AAAAA "));
P = (char *) BUF. PTR ();

4. UTF-8 to Unicode

Cnvutfconverter: converttounicodefromutf8 (ibuf16, ibuf8 );

5. Unicode conversion to UTF-8

Cnvutfconverter: convertfromunicodetoutf8 (ibuf8, ibuf16 );

6. convert a char string to a Symbian string

Char * Cc = "aaaa ";
Tptrc8;
A. Set (const tuint8 *) CC, strlen (CC ));

Add one more:

Tdesc8 & Buf;
Tuint8 * pdata;
Pdata = Buf. PTR ();
Then, this pdata can be used as an unsigned char *, which is important for network communication.
If pdata is damaged, you can
Tbuf8 <1024> tmp_buf;
Tmp_buf.copy (BUF );
Pdata = tmp_buf.ptr ();
In this way, you can protect the data of the Buf, especially if the data received by the socket is allocated by the receiving function.

Strcpy

Prototype: extern char * strcpy (char * DEST, char * SRC );
Usage: # include <string. h>
Function: Copies the string ending with null indicated by Src to the array indicated by DeST.
Note: The memory areas specified by Src and DEST cannot overlap and DEST must have sufficient space to accommodate SRC strings.

Returns the pointer to DeST.

Memcpy

Prototype: extern void * memcpy (void * DEST, void * SRC, unsigned int count );
Usage: # include <string. h>
Function: copy count bytes from the memory area indicated by Src to the memory area indicated by DeST.
Note: the memory areas specified by Src and DEST cannot overlap. The function returns a pointer to DeST.

Memset

Prototype: extern void * memset (void * buffer, int C, int count );
Usage: # include <string. h>
Function: sets the first count byte of the memory area referred to by buffer to character C.
Note: The pointer to the buffer is returned.

------------------------------------------------------------------------------

Convert tdesc type to char * type

Const char * CP = reinterpret_cast <const char *> (DESC. PTR (); // or use ptrz ()
Char * P = const_cast <char *> (CP );

Remember that the length of the string is desc-> size () (or desc-> length () * 2), and the max length of the string is desc-> maxlength () * 2 (including the '/0' Terminator, if any ).

For details, see:
"Conversion bitween 8 and 16 bits Descriptors"
Http://forum.newlc.com/index.php/topic,1075.0.html

 

----------------------------------------------------------------------------------

Http://www.sf.org.cn/Article/symbiandev/200511/2577.html

Here are some introductions about descriptors. If you are interested, please refer to them.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.