Service: Code-Beispiele: CStringCH: Quellcode
/* * StringCH.h : Header-File to CStringCH class * Extends CString. 1st implementation contains generic 'Split()'. * 1st Extension: 'Fill()'. * Hints: * Derived from CString * Also add StringCH.cpp to your project file. * You may ask yourself "What is this about the weired 'CH' name suffix?" * I didn't want to name my CString class extension 'CStringExt' because * almost every extended of every programmer might be named 'CStringExt'. * CH means CodeHelper. I think, that there is a good chance, my CStringCH * will never have a name confict with another CString class extension. */ #if !defined(STRINGCH_H__E5DB739E_213D_468D_9371_BD8E4FC99309__INCLUDED_) #define STRINGCH_H__E5DB739E_213D_468D_9371_BD8E4FC99309__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include <afx.h> #include <afxwin.h> // MFC Core- and Standardcomponents #include <afxext.h> // MFC Extensions #include <afxtempl.h> class CStringCH: public CString { public: /* Overwritten construtors of base class. * Initialize necessary member variables */ CStringCH( ); CStringCH( const CString& stringSrc ); CStringCH( TCHAR ch, int nRepeat = 1 ); CStringCH( LPCTSTR lpch, int nLength ); CStringCH( const unsigned char* psz ); CStringCH( LPCWSTR lpsz ); CStringCH( LPCSTR lpsz ); /* Overwritten destrutor of base class. Delete member variables*/ ~CStringCH(); /* * Fillup the string using space character * @param short nRepeat: Number of charaters to be filled in */ voidFill(short nRepeat); /* * Fillup the string using space character * @param int nRepeat: Number of charaters to be filled in */ voidFill(int nRepeat); /* * Fillup the string using space character * @param long nRepeat: Number of charaters to be filled in */ voidFill(long nRepeat); /* * Fillup the string using a certain character * @param short nRepeat: Number of charaters to be filled in * @param WCHAR wcCharacter: The charater to be filled in */ voidFill(short nRepeat, WCHAR wcCharacter); /* * Fillup the string using a certain character * @param int nRepeat: Number of charaters to be filled in * @param WCHAR wcCharacter: The charater to be filled in */ voidFill(int nRepeat, WCHAR wcCharacter); /* * Fillup the string using a certain character * @param long nRepeat: Number of charaters to be filled in * @param WCHAR wcCharacter: The charater to be filled in */ voidFill(long nRepeat, WCHAR wcCharacter); /* * Do a 'split' on the current string using the delimiter passed in as * parameter. The 'Split Results' are copied to CStringArray. If split * failed because string is empty or delimiter is not in string, * CStringArray will contain one item (empty string or the hole * (unsplitted) string. Mulitple call is harmless though split will * just be redone each time. * @param The Delimiter */ voidSplit(const CString& Delimiter); /* * Return number of 'CString's in CStringArray build by 'Split()'. */ intGetSplitCount(); /* * Return CStringArray representing the result of 'Split()'. */ CStringArray*GetSplitResults(); /* * Return CMapStringToString representing the result of 'Split()'. */ CMapStringToString*GetSplitResultsMap(); private: /* * Create necessary pointer variables on heap */ voidInitialize(); /* * CStringArray representing the result of 'Split()'. */ CStringArray*m_pSplitResults; /* * CMapStringToString representing the result of 'Split()'. */ CMapStringToString*m_pSplitResultsMap; /* * Fillup the string using a certain character * @param long nRepeat: Number of charaters to be filled in * @param WCHAR wcCharacter: The charater to be filled in */ voidFillInt(long nRepeat, WCHAR wcCharacter); }; #endif // !defined(STRINGCH_H__E5DB739E_213D_468D_9371_BD8E4FC99309__INCLUDED_)
/*
* StringCH.cpp : Implementation-File to CStringCH class
* Hints:
* Also add StringCH.h to your project file and
* '..\Libs' as additional include folder
*/
#include <StringCH.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CStringCH::CStringCH( )
:CString()
{
Initialize();
}
CStringCH::CStringCH( const CString& stringSrc )
:CString( stringSrc )
{
Initialize();
}
CStringCH::CStringCH( TCHAR ch, int nRepeat )
:CString( ch, nRepeat )
{
Initialize();
}
CStringCH::CStringCH( LPCTSTR lpch, int nLength )
:CString( lpch, nLength )
{
Initialize();
}
CStringCH::CStringCH( const unsigned char* psz )
:CString( psz )
{
Initialize();
}
CStringCH::CStringCH( LPCWSTR lpsz )
:CString( lpsz )
{
Initialize();
}
CStringCH::CStringCH( LPCSTR lpsz )
:CString( lpsz )
{
Initialize();
}
CStringCH::~CStringCH()
{
// Free memory
if (m_pSplitResults)
{
if (m_pSplitResults->GetSize())
m_pSplitResults->RemoveAll();
delete m_pSplitResults;
}
m_pSplitResults = NULL;
if (m_pSplitResultsMap)
{
if (m_pSplitResultsMap->GetCount())
m_pSplitResultsMap->RemoveAll();
delete m_pSplitResultsMap;
}
m_pSplitResultsMap = NULL;
}
void CStringCH::Initialize()
{
// Create necessary pointers to member variables
m_pSplitResults = new CStringArray;
m_pSplitResultsMap = new CMapStringToString;
}
void CStringCH::Fill(int nRepeat)
{
WCHAR wcCharacter = ' ';
FillInt((long)nRepeat, wcCharacter);
}
void CStringCH::Fill(short nRepeat)
{
WCHAR wcCharacter = ' ';
FillInt((long)nRepeat, wcCharacter);
}
void CStringCH::Fill(long nRepeat)
{
WCHAR wcCharacter = ' ';
FillInt(nRepeat, wcCharacter);
}
void CStringCH::Fill(int nRepeat, WCHAR wcCharacter)
{
FillInt((long)nRepeat, wcCharacter);
}
void CStringCH::Fill(short nRepeat, WCHAR wcCharacter)
{
FillInt((long)nRepeat, wcCharacter);
}
void CStringCH::Fill(long nRepeat, WCHAR wcCharacter)
{
FillInt(nRepeat, wcCharacter);
}
void CStringCH::FillInt(long nRepeat, WCHAR wcCharacter)
{
for (long i = GetLength(); i < nRepeat; i++)*this += _T(wcCharacter);
}
void CStringCH::Split(const CString& Delimiter)
{
int iPos = 0;
int newPos = -1;
int sizeS2 = Delimiter.GetLength();
int isize = this->GetLength();
CArray
Wenn Sie wissen wollen, was so alles auf Ihrem PC passiert!
Tischrechner als Software.
Jetzt herunterladen und kostenlos testen!
Tastenkombinationen können PC-Arbeit erheblich beschleunigen.
Eine Reihe von kostenlosen Online-Berechnungen zur Erleichterung der täglichen Arbeit.
Sicherheit im PC-Bereich
Es existiert eine kostenlose, einfache und äußert effektive Methode, fast alle Viren, Trojaner, Würmer ...