Dated: 18/12/24
Programming Fundamentals Lab Assignment
STRINGS
Strings are used to represent text. They are set of characters that can also contain
alphabets, spaces, numbers and other symbols. Strings can be implemented using
<string> library.
STRING FUNCTIONS
1. Length/Size
o Returns the number of characters in the string.
o Implementation: length() / size()
2. Append
o Adds the specified string (str) to the end of the current string.
o Implementation: append(str)
3. Insert
o Inserts the specified string (str) at position pos in the current string.
o Implementation: insert(pos, str)
4. Substring
o Returns a substring starting at position pos with length len.
o Implementation: substr(pos, len)
5. Find
o Searches for the first occurrence of the substring (str) and returns its index.
o Implementation: find(str)
6. Erase
o Removes len characters starting from position pos.
o Implementation: erase(pos, len)
Exercise:
Question 1: Write any simple program to demonstrate the use of the given string
functions from the string library. Implement each function at least once in your
program with proper input and output.