README.md
December 5, 2022 ยท View on GitHub
Description
I just started learning C++ and had to do some string parsing code for one of my classes. I couldn't figure out how to do it until later on, but I wrote these little functions to help those that learned in VB feel a little more at home in C++. At least when they deal with strings.
More Info
| Submitted On | |
| By | DarkMercenary44 |
| Level | Beginner |
| User Rating | 4.5 (18 globes from 4 users) |
| Compatibility | C++ (general), Microsoft Visual C++, UNIX C++ |
| Category | Strings |
| World | C / C++ |
| Archive File |
Source Code
Pretty much just copy and paste these functions in your file, I would've made a header file but don't know how yet.
Note: Make sure you include the string.h or just #include
Function Prototypes:
string mid( int, int, string);
int instr( int, string, string );
string sleft( string, int );
string sright( string, int );
Function Definitions:
string mid( int posStart, int intLen, string strSearch )
{
return strSearch.substr(posStart, intLen);
}
int instr(int startPOS, string strSearch, string strFind)
{
//return strSearch.find(strFind);
return strSearch.find(strFind, startPOS);
}
string sleft(string strSearch, int intLen)
{
return strSearch.substr(0, intLen);
}
string sright(string strSearch, int intLen)
{
return strSearch.substr(strSearch.length() - intLen, intLen);
}