Extracting a Substring from a String: substr()

substr() extracts part of a string, leaving the original string unchanged. It takes two parameters of type string::size_type:  the first is the position to start extracting, and the second is the number of characters to extract.  It returns a substring consisting of the extracted characters. If you omit the second parameter, substr() will extract characters from the starting position and be continuing to the end of the string.
Syntax: result_string = source.substr(starting_pos,numchars);
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: