c substring
Posted: May 30th, 2004, 2:27 am
C++ is a fairly complicated language, dealing directly with memory management. Here's an example of the memory management put to use. The following functions are named and set up identically to the VB versions with mid, left, and right functions.
To use these functions, call them like this:
mid((char*) str, 3, 5)
This would return a substring of the character array str starting at character 3 and ending at 5. Note that the string parameter cannot be a quoted string, only a character array.
It might not make sense how this works to you, but I'll try to get a C++ Memory Pointers tutorial out soon. I'm really bad with deadlines, so I won't set one.
Post any problems or comments.
Code: Select all
char * left(char * string, int length)
{
string[length] = 0;
return string;
}
char * right(char * string, int length)
{
string += strlen(string) - length;
return string;
}
char * mid(char * string, int start, int length)
{
string += start;
string[length] = 0;
return string;
}
mid((char*) str, 3, 5)
This would return a substring of the character array str starting at character 3 and ending at 5. Note that the string parameter cannot be a quoted string, only a character array.
It might not make sense how this works to you, but I'll try to get a C++ Memory Pointers tutorial out soon. I'm really bad with deadlines, so I won't set one.
Post any problems or comments.