VB String Functions (left, right, isntr, mid) very easy code...

Submitted on: 1/5/2015 12:19:00 AM
By: DarkMercenary44 (from psc cd)  
Level: Beginner
User Rating: By 4 Users
Compatibility: C++ (general), Microsoft Visual C++, UNIX C++
Views: 1068
     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.


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);

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.