How to convert between TDes8 and TDes16
6 Oct 2003 - 12:38

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

Tutorial posted October 6th, 2003 by eric

Submitted by bertq (not verified) on Thu, 2003-10-09 16:48.

Hi,

In most cases, just using the Copy() function of the descriptor is enough to convert TDes8 to TDes16 and vice-versa. I think the article should mention about this.

TBuf16 <100> a; TBuf8 <100> b;

b.Copy(a);

Very useful article anyway !

 berthier


Submitted by Rajesh (not verified) on Tue, 2004-07-27 13:44.

Thanks a lot Berthier,what you said really works and its simpler too.Had to burn my brain for an hour,then had the great idea of looking for it here on newlc.com

Thanks Again


Submitted by kougi (not verified) on Wed, 2004-12-15 12:10.

Thanks.. This made my life much more easier.. :P

Submitted by shereen_shaaban (not verified) on Sat, 2005-04-09 19:18.

I tried this code TBuf16<100> a; TBuf8<100> b;

b.Copy(a)

i've included #include <utf.h> and have added charconv.lib and seem to be getting a link error.

Undefined Symbol: TParse::'TParse(void) (??0TParse@@QAE@XZ)'

Could anyone tell me what i'm missing?

Thanks.


Submitted by Anonymous on Sun, 2003-10-26 08:30.

have you ever tried this function CnvUtfConverter::ConvertFromUnicodeToUtf8() successfully? i had a link error, "unresolved external link" while linking... and another function CnvUtfConverter::ConvertToUnicodeFromUtf8() works well here... i dont know why and guess probably its a corruption of charconv.lib. would you fellows like to verify that for me or give me some suggestions if you tried succesfully, regards!

Submitted by Anonymous on Fri, 2004-02-13 06:22.

you need to link against charconv.lib


copyright 2003-2009 NewLC SARL