Hello CodeForces
Here is some common string operations.
______**Accessing character**______ front -> Access the first first character Example: char ch = string_name.front(); back -> Access the last character Example: char ch = string_name.back(); at -> Access the specified character Example: char ch = string_name.at(position); //Here position maybe 0 to length-1
_____**Operations**_____ clear -> Clears the content Example: string_name.clear();
push_back -> Appends a character to the end Example: string_name.push_back('C'); // Here 'C' appends pop_back -> Removes the last character Example: string_name.pop_back();
_____**Special**_____ string str(x, ch); str is any stiring variable. x is any integer value. ch is any character. the expressions means 'str' store x time(s) ch. Example: string str(3, 'z'); // now str = "zzz". Try it
_____**Iteration**_____ begin -> Returns an iterator to the beginning end -> Returns an iterator to the end rbegin -> Returns a reverse iterator to the beginning rend -> Returns a reverse iterator to the end Using these itarator we can sort or reverse an string Example: To sort elements in ascending order sort(string_name.begin(), string_name.end()); To sort elements in descending order sort(string_name.rbegin(), string_name.rend()); To reverse string reverse(string_name.begin(), string_name.end());
All of the syntax are written in C++ language. Discussions welcome in the comment section. For more information or reference, visit: https://en.cppreference.com/w/cpp/string/basic_string



