Professional Documents
Culture Documents
OOP - String Class Questions
OOP - String Class Questions
Implement the class String which must perform the following tasks between various strings.
13. Tokenization //same as split, pass list of characters or string, returns a string array split based
on delimiters
■ Mystring* tokenize(const char* delim, int& count) const;
Tokenize (“, .”, count)
14. String concatenation //adds two strings and returns resultant string
■ Mystring concat(const Mystring& s2)const; // MyString s(“abc”), s2(“def”);
■ Mystring& append(const Mystring& s2); // MyString s3 = s.concat(s2);
// s.append(s2); s.print();
16. Find
■ First
■ Int find_first(char ch); // returns first index at which character is found
■ int find_first(const Mystring &) const; // returns first index at which string is found
■ Last
■ Int find_last(char ch); // returns last index at which character is found
■ int find_last(const Mystring&) const; // returns last index at which string is found
■ All
■ int* find_all(char ch, int &C); // returns pointer to an array of indices at which
character is present
■ int* find_all(const mystring &, int& C )const; // returns an array of indices at which
string is present
Mystring s1=”zabcdeaaa”;
int C;
int first= s1. find_first(‘a’); //first=1
int last=s1.find_last(‘a’); // last=8
int *indices= s1.find_all(‘a’, C); // indices contain {1,6,7,8} and C = 4
19. void insert_at(int i, const Mystring sub); // Add a string at given position
Mystring s1=”Sarfraz”
s1.clear()
//s1 becomes “”
22. ~MyString(); // Destructor