Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
const char * -- utf-8 vs ANSIExplains the "Utf8" property that is common to all Chilkat C++ classes.
#include <CkEmail.h> #include <CkString.h> void ChilkatSample(void) { // All Chilkat C++ classes have a "Utf8" bool property (i.e. there // is a get_Utf8() method, and a put_Utf8(bool newval) method. // When a Chilkat method returns a "const char *", or if // a method argument is a "const char *", it is by default // an ANSI string. However, if the Utf8 property is set to true, // then "const char *" is a utf-8 string. This means you may // pass utf-8 strings to Chilkat methods, and Chilkat methods // may return utf-8 strings. // For example, here's how to get an email's Subject as // either a utf-8 or ANSI string. CkEmail email; bool success; success = email.LoadEml("someEmail.eml"); if (success != true) { printf("%s\n",email.lastErrorText()); return; } const char * ansiStr; const char * utf8Str; // By default, "const char *" is ANSI: ansiStr = email.subject(); // Set the Utf8 property = true to get the subject // as a utf-8 string: email.put_Utf8(true); utf8Str = email.subject(); // When passing "const char *" to other Chilkat object, // make sure the Utf8 properties agree. CkString strObj; // The following line is incorrect, because by default a Chilkat object // interprets "const char *" as ANSI characters, not utf-8: strObj.append(utf8Str); // The correction is to set Utf8 = true strObj.put_Utf8(true); strObj.append(utf8Str); // To get a wchar_t *, call CkString::getUnicode // wchar_t *wideStr = strObj.getUnicode(); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.