FA> Is there any MID$ BASIC-like function in C or C++?
FA> (I'm using TC and TC++ (both by Borland, of course)....
There is a complete set of BASIC-like string handling
routines in SNIPPETS. Simply, however, you may do this.
I suppose I should have some check for a NULL pointer in
my constructor as well.
/*_|_| MID.CPP PUBLIC DOMAIN by Kurt Kuzba 9/21/1997
_|_|_| Simple demonstration of a BASIC-like MID$ class.
_|_|*/
#include
#include
class Mid_String
{
public:
Mid_String(char*, int);
~Mid_String(void);
char *String(void){ return pszM; }
private:
char *pszM;
};
Mid_String::Mid_String(char *pszS, int iLen = 0)
{
int iSlen = strlen(pszS);
pszM = new char[iSlen];
strcpy(pszM, pszS);
if(iLen && iLen < iSlen)
*(pszM + iLen) = '\0';
}
Mid_String::~Mid_String(void)
{
delete []pszM;
}
int main(void)
{
char *pszMystring = "This is a test string";
Mid_String *Mid = new Mid_String (pszMystring, 5);
cout String() << flush;
delete Mid;
Mid = new Mid_String (pszMystring + 5, 3);
cout String() << flush;
delete Mid;
Mid = new Mid_String (pszMystring + 8, 2);
cout String() << flush;
delete Mid;
Mid = new Mid_String (pszMystring + 10);
cout String() << flush;
delete Mid;
Mid = new Mid_String (pszMystring);
cout String() << "." << endl;
return 0;
}
> ] What do you mean, "There is more to life than computers."?..
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)
|