首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Symbian英文资料 >> base >> 正文
How to convert between TDes8 and TDes16
作者:佚名    文章来源:不详    更新时间:2006-5-7 10:58:33

Conversion between TDes8 and TDes16 is a common headache in Symbian development. At least for developpers used to work with 8 bits character coding.

Symbian’s CnvUtfConverter class is a powerful framework to handle character conversions to and from UTF8 (i.e TDes8). In most cases however, you only handle plain ASCII characters, using TDes8 to read/write to a file or a socket and TDes/TDes16 for the internal handling of the data. The following usage of CnvUtfConverter is suitable in this case (KErrNone is return in case of success, a positive value represents the number of aFrom characters not converted):


#include <utf.h> // charconv.lib

TInt NNewLCUtils::ConvertTDes8ToTDes16(const TDesC8& aFrom, TDes16& aTo)
{
 return(CnvUtfConverter::ConvertToUnicodeFromUtf8(aTo,aFrom));
}

TInt NNewLCUtils::ConvertTDes16ToTDes8(const TDesC16& aFrom, TDes8& aTo)
{
 return(CnvUtfConverter::ConvertFromUnicodeToUtf8(aTo,aFrom));
}

If you are dealing with UTF-7 (RFC-2152), you can also take a look at the ConvertFromUnicodeToUtf7 / ConvertFromUnicodeToUtf7 methods (note that there is no direct convesion between UTF-7 and UTF-8).

相关文章:
没有相关文章
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号