Common string operations

Revision en2, by sajeeb02, 2023-03-03 06:27:37
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

Tags string, string operations, cp string

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English sajeeb02 2023-03-03 06:29:23 100
en2 English sajeeb02 2023-03-03 06:27:37 34
en1 English sajeeb02 2023-03-03 06:27:05 1694 Initial revision (published)