Data Type Conversion
1. String to Digit
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.