Below is the code of StringUtil.cpp and StringUtil.h
//******* STRINGUTIL.CPP *************
#include "StringUtil.h"
#include <string.h>
#include <stdlib.h>
#ifdef WIN32
#include <tchar.h>
#endif
#include <string>
StringUtil::StringUtil()
{
m_initialized = true;
}
StringUtil::StringUtil (const long int& src)
{
char *buf =new char[MAX_STRING_SIZE];
sprintf(buf,"%ld",src);
m_str = buf;
m_initialized = true;
delete buf;
}
StringUtil::StringUtil (const string& src)
{
m_str = src;
}
StringUtil::StringUtil (const char* src)
{
string tmpStr(src);
m_str = tmpStr;
}
StringUtil::StringUtil(const StringUtil& objStringUtil)
{
m_str = objStringUtil.m_str;
m_initialized = objStringUtil.m_initialized;
}
StringUtil::~StringUtil()
{
}
long StringUtil::getLength() const
{
return (m_str.length());
}
StringUtil& StringUtil:

perator=(const char* str1)
{
string tmpStr(str1);
m_str = tmpStr;
return (*this);
}
StringUtil& StringUtil:

perator=(const StringUtil& src)
{
m_str = src.m_str;
m_initialized = src.m_initialized;
return *this;
}
StringUtil operator + (const StringUtil& str1, const StringUtil& str2)
{
StringUtil tmpStr;
tmpStr.m_str = str1.m_str + str2.m_str;
return tmpStr;
}
StringUtil operator+ (const StringUtil& s1, const long int& s2)
{
StringUtil tmpStr;
char *buf =new char[MAX_STRING_SIZE];
sprintf(buf,"%ld",s2);
tmpStr.m_str = s1.m_str + buf;
delete buf;
return tmpStr;
}
int StringUtil::extractString(int pos1, int pos2, StringUtil& result)
{
// Errinfo status = SUCCESS;
const int incr1 = pos1;
const int incr2 = pos2;
string oldStr = (*this).m_str;
string newStr = oldStr.substr(incr1, incr2);
result.m_str = newStr;
return 0;// SUCCESS;
}
int StringUtil::findAndReplace(const StringUtil& pattn, const StringUtil& repl, bool bFindOnly, StringUtil& result)
{
// Errinfo status = SUCCESS;
// unsigned int iPos;
if( bFindOnly == false ) {
int ilen = pattn.getLength();
int iReplen = repl.getLength();
int i = m_str.find(pattn.m_str);
while ( i >= 0 ) {
m_str.replace(i,ilen,repl.m_str);
i = m_str.find(pattn.m_str,i+iReplen);
}
}
result.m_str = m_str;
return 0;// status;
}
int StringUtil::compare(const StringUtil& str1, const StringUtil& str2) const
{
if(!str1.m_str.compare(str2.m_str))
return 1;
return 0;
}
StringUtil StringUtil::trim()
{
int nPos = m_str.find_first_not_of(" ");
if(nPos >=0) {
m_str = m_str.substr(nPos,m_str.length());
int oPos = m_str.find_last_not_of(" ");
if(oPos>=0)
m_str = m_str.substr(0,oPos+1);
}
return (*this) ;
}
StringUtil StringUtil::toUpper()
{
int length = (*this).getLength();
for(int index=0;index<length;index++)
m_str[index] = toupper(m_str[index]);
return (*this);
}
int StringUtil::fillData(int iPos,char* cTemp)
{
int iStrLen = m_str.length();
if (iStrLen > iPos)
{
m_str.replace(iPos, strlen(cTemp),cTemp);
return 0;
}
while(iStrLen < iPos)
{
m_str.insert(iStrLen," ");
iStrLen++;
}
m_str.insert(iPos,cTemp);
printf("After Insert Value\n");
return 1;
}
int StringUtil::fillRepeatData(int iPos,char cTemp,int iCount)
{
char cTmp[3];
cTmp[0] = cTemp;
cTmp[1] = '\0';
int iStrLen = m_str.length();
if(iStrLen < iPos)
{
while(iStrLen < iPos)
{
m_str.insert(iStrLen," ");
iStrLen++;
}
}
while(iStrLen < iCount+iPos)
{
m_str.insert(iStrLen,(char*)cTmp);
iStrLen++;
}
return 1;
}
void StringUtil::retrieveData(int iPos, int iLen, char *pcVal)
{
m_str.copy(pcVal,iLen,iPos);
//size_type copy(charT* buf, size_type n, size_type pos = 0) const
}
//************** STRINGUTIL.H ********************
#ifndef STRING_UTIL_H
#define STRING_UTIL_H
#include <string>
//#include <string.h>
#include <iostream.h>
#include <list>
#define MAX_STRING_SIZE 50
class StringUtil {
public:
StringUtil();
StringUtil(const string&);
StringUtil (const char* ); // constructor
StringUtil (const long int&);
StringUtil(const StringUtil&);
~StringUtil();
const char* getString() const;
long int getLength () const;
StringUtil& operator= (const char* ); // assignment from ccharp
StringUtil& operator= (const StringUtil&); // assignment from StringUtil
StringUtil& operator= (const long int&); // assignment from an Int object
bool operator!= (const StringUtil& s) const;
// extracting strings given the from position(pos1) and the
// to position(pos2)
int extractString(int pos1, int pos2, StringUtil& result);
// find if the current object contains a certain string.
// if the third parameter is set to true, it will only try to find if the
// string exists
// If the third parameter is set to false, it will find and also replace the
// string with the replacement string
int findAndReplace(const StringUtil& pattn, const StringUtil& repl,bool bFindOnly, StringUtil& result);
//compares two string objects and returns TRUE or FALSE
int compare(const StringUtil& str1, const StringUtil& str2) const;
StringUtil toUpper() ; // return lowercase value
StringUtil trim(); // return string without both leading & trailing spaces
int fillData(int iPos,char* cTemp);//similiar like the SetAt in CString
int fillRepeatData(int iPos,char cTemp,int iCount); // Inserts a charecter a specified number of times.
void retrieveData(int iPos, int iLen, char *pcVal); // acts like substr
friend StringUtil operator+ (const StringUtil& s1, const StringUtil& s2);
friend StringUtil operator+ (const StringUtil& s1, const long int& s2);
bool operator< (const StringUtil& s) const;
bool operator> (const StringUtil& s) const;
bool operator<= (const StringUtil& s) const;
bool operator>= (const StringUtil& s) const;
bool operator==(const StringUtil&);
bool operator==(const char* s2);
virtual void display (ostream& oStr) const; // used by the << operator.
friend ostream& operator<< ( ostream& oStr, const StringUtil& str1 )
{
str1.display(oStr);
return oStr;
}
bool is_initialized() const;
private:
string m_str;
bool m_initialized;
};
inline bool StringUtil:

perator<(const StringUtil& s) const
{
return(m_str < s.m_str);
}
inline bool StringUtil:

perator>(const StringUtil& s) const
{
return(m_str > s.m_str);
}
inline bool StringUtil:

perator<=(const StringUtil& s) const
{
return(m_str <= s.m_str);
}
inline bool StringUtil:

perator>=(const StringUtil& s) const
{
return(m_str >= s.m_str);
}
inline bool StringUtil:

perator== (const StringUtil& str)
{
return(!m_str.compare(str.m_str));
}
inline bool StringUtil:

perator==(const char* s2)
{
string tmpBuffer(s2);
return(!m_str.compare(tmpBuffer));
}
inline bool StringUtil:

perator!=(const StringUtil& s) const
{
return(m_str.compare(s.m_str) != 0);
}
inline bool StringUtil::is_initialized() const
{
return (m_initialized);
}
inline void StringUtil::display(ostream& oStr) const
{
oStr << m_str << endl;
}
inline const char* StringUtil::getString() const
{
return m_str.c_str();
}
#endif