/*###############################################################################################*/
//# File Name : StringFunctions.cpp #
//# Version : 1.0.1 #
//# Created By : Technocrat (Technocrat498@yahoo.com) #
//# Date : 3/20/02 #
//# Completed : W/I/P #
//# Mod : 3/25/02 #
//# Changed IsNumeric, Upcase & Lowercase To Have Loops To Use Pointers #
//# Thanks To jim mcnamara #
//# Does : Contains The Following Functions: #
//# IsNumeric (Checks To See If A Char Or String Is Numeric) #
//# Upcase (Uppercases A Char Or String) #
//# Lowercase(Lowercases A Char Or String) #
//# Trim (Trims The Spaces At The End Of A String Of Chars) #
//# RTrim (Trims The Spaces To The Right Of A String Of Chars) #
//# LTrim (Trims The Spaces To The Left Of A String Of Chars) #
//# right (Trims Chars From Right To Left Of A String) #
//# left (Trims Chars To From Left To Right Of A String) #
//# mid (Trims Chars To From A Position To Right Of A String) #
//# Notes : The Header File (StringFunctions.h) Must Be Included #
//# Reason : To hold all these functions in a classes in one cpp so I can use them in any#
//# program. #
//# Thanks : Parksie, jim mcnamara, CornedBee, Kedaman and Zaei on the VB-World.net #
//# C/C++ Forums for all their help with this and other C/C++ projects #
//# Megatron on the VB-World.net Forums for helping me with more problems than #
//# I care to count. With out his help I would have quit programming along #
//# time ago. #
/*###############################################################################################*/
/*-----------------------------*/
//Include
#include "StringFunctions.h"
/*-----------------------------*/
//Global
/*-----------------------------*/
//.cpp Global
/*-----------------------------*/
//.cpp Functions
/*-----------------------------*/
/*##############################################################################################*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//| Function: IsNumeric()
//| In: char *chString
//| In Char Or String Of Chars
//| Return: BOOL
//| Notes: This Function Checks To Is If A Char Or A String Of Chars Is Numeric Or Not
//| Example: char p[] = "5";
//| BOOL bRet = FALSE;
//| bRet = IsNumeric(p); //Should Return True
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
BOOL IsNumeric(char *chString)
{
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
char *buf; //Temp Char VAR
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
buf = chString;
//Loop Through The Pointer Using The Inline Function IsDigit
while (IsDigit(buf))
{
buf++; //Increase The Pointer
}
return (BOOL) (*buf==0x00);
}
/*##############################################################################################*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//| Function: IsNumeric()
//| Overload Function
//| In: string *stString
//| In String Pointer
//| Return: BOOL
//| Notes: This Function Checks To Is If A String Of Chars Is Numeric Or Not
//| Example: string p = "5";
//| BOOL bRet = FALSE;
//| bRet = IsNumeric(&p); //Should Return True
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
BOOL IsNumeric(string *stString)
{
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
static char chTemp; //Temp Char VAR
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
//Loop Through The Length Of The Input
for(unsigned int i=0; i < stString->length(); i++ )
{
//Copy One Char At A Time To The Temp Char VAR
strcpy(&chTemp,stString->substr(i,1).c_str());
//If The Inline Function IsDigit Returns A False And It Is Not A .
if(!IsDigit(&chTemp))
return FALSE;
}
return TRUE;
}
/*##############################################################################################*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//| Function: Upcase()
//| In: char *chString
//| In Char Or String Of Chars
//| Return: None
//| Notes: This Function Uppercases A Char Or Sting Of Chars
//| Example: char p[] = "t";
//| Upcase(p); //Should Chang p To T
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void Upcase(char *chString)
{
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
string stTemp = ""; //Temp String VAR
char *buf;
unsigned int i =0;
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
buf = chString;
//Loop Through The Length Of The Pointer
while(*buf != 0x00)
{
//Make The Temp VAR Set To The Uppercase Of The Input VAR
stTemp += ToUpper(chString[i]);
buf++;
i++;
}
try
{
//Copy Back
strcpy(chString,stTemp.c_str());
}
catch(...)
{
return;
}
}
/*##############################################################################################*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//| Function: Upcase()
//| Overload Function
//| In: string *stString
//| In Char Or String Of Chars
//| Return: None
//| Notes: This Function Uppercases A Char Or Sting Of Chars
//| Example: string p = "t";
//| Upcase(p); //Should Chang p To T
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void Upcase(string *stString)
{
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
string stTemp = ""; //Temp String VAR
static char chTemp; //Temp Char VAR
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
//Loop Through The Length Of The Input
for(unsigned int i=0; i<stString->size(); i++)
{
//Copy One Char At A Time To The Temp Char VAR
strcpy(&chTemp,stString->substr(i,1).c_str());
//Make The Temp VAR Set To The Uppercase Of The Input VAR
stTemp += ToUpper(chTemp);
}
try
{
//Copy Back
memcpy(stString,&stTemp,sizeof(stTemp));
}
catch(...)
{
return;
}
}
/*##############################################################################################*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//| Function: Lowercase()
//| In: char *chString
//| In Char Or String Of Chars
//| Return: None
//| Notes: This Function Lowercases A Char Or Sting Of Chars
//| Example: char p[] = "T";
//| Lowercase(p); //Should Chang p To t
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void Lowercase(char *chString)
{
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
string stTemp = ""; //Temp String VAR
char *buf;
unsigned int i =0;
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
buf = chString;
//Loop Through The Length Of The Pointer
while(*buf != 0x00)
{
//Make The Temp VAR Set To The Lowercase Of The Input VAR
stTemp += ToLower(chString[i]);
buf++;
i++;
}
//Copy Back
strcpy(chString,stTemp.c_str());
}
/*##############################################################################################*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//| Function: Lowercase()
//| Overload Fu