Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CStringW and CStringA

0.00/5 (No votes)
29 Jun 2002 2  
CStringW and CStringA for WTL

Introduction

After doing endless string programming I got sick of doing string conversion and so split CString into a UNICODE and ANSI version (CStringW and CStringA). I replicated the WTL string class and replaced the internal data representation from TCHAR to wchar_t for CStringW and char for CStringA, modifying all functions depending on the internal data representation.

The classes behave exactly like CString. Just include "StringA.h" and "StringW.h" like you include "atlmisc.h". Even _ATL_MIN_CRT is supported. It's the same like MFC 7.0 is doing it, which gave me the inspiration by the way.

If you want to see unicode strings while debugging, don't forget to switch on Tools/Options/Debug/Display unicode strings. Which is not enabled by default.

Additionally you shoud modify your Autoexp.dat file to see the content of CStringW and CStringA like you are used from CString.

Add these two lines into the section [AutoExpand]:

CStringW =<m_pchData,su>
CStringA =<m_pchData,s>

Example

#include "StringA.h"

#include "StringW.h"


CStringW sTestW( L"Test" );
CStringA sTestA( "Test" );

// convert

CStringW sConvertW = sTestA;
CStringA sConvertA = sTestW;

I couldn't test all functions and probably some constructors are missing. If you find an error or have a suggestion please feel free and add a message to the discussion.

I hope you'll like and use it.
Oskar

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here