Section 10.2 Freestyle Exercise
#
Question
Your Answer
Result / Explanation
10.2.1
Write a statement that appends s2 into s1 using the append function.
10.2.2
Write a statement that assigns the first 4 characters in s2 into s1 using the assign function.
10.2.3
Write an expression that returns a C-String from string s using the c_str() function.
10.2.4
Assume s is a string with value "abc", what is s.compare(string("abc"))?
10.2.5
Write an expression that returns position of the first matching substring "abc" in string s.
10.2.6
Write an expression that returns a substring of three characters from s starting at index 1.
10.2.7
Write a statement that inserts string s2 into string s1 at index 2.
10.2.8
Write a statement that replaces 5 characters in string s1 starting at position 2 with string s2.
10.2.9
Write an expression that returns the first character from string s using the subscript operator.
10.2.10
Write an expression that returns the last character from string s using the subscript operator and the length function.
10.2.11
Suppose s is a string with value "abcdef", what is s after executing the statement s.replace(s.find("cd"), 3, "CD")?