std::string

Replace Last Character of a String in C++

In this article, we will discuss different ways to replace last character of a string with another character in C++. Table Of Contents Using subscript operator Using string::replace() function Using string::at() function Using string::substr() Suppose we have a string like this, We want to replace the last character of this string with character ‘X’. The …

Replace Last Character of a String in C++ Read More »

Replace First Character in a string in C++

In this article, we will discuss different ways to replace first character of a string with another character in C++. Table Of Contents Using subscript operator Using string::replace() function Using string::at() function Using string::substr() Suppose we have a string like this, We want to replace the first character of this string with character ‘X’. The …

Replace First Character in a string in C++ Read More »

Replace all occurrences of a character in String in C++

In this article, we will discuss different ways to replace all occurrences of a character from a string with an another character in C++. Table Of Contents Using STL Algorithm std::replace() Using string::replace() and find() Using Iteration Suppose we have a string, We want to replace all the occurrence of character ‘e’ with ‘P’ in …

Replace all occurrences of a character in String in C++ Read More »

Remove Newline Characters from a String in C++

In this article, we will discuss different ways to remove all newline characters from a string in C++. The new line characters can be ‘\n’ or ‘\r’. Table of Characters Remove Newline characters from String using Regex Remove Newline characters from String using remove_if() & string::erase() Remove Newline characters from String using std::erase_if() in C++20 …

Remove Newline Characters from a String in C++ Read More »

How to Remove a Character from String in C++

In this article, we will discuss different ways to remove all occurrences of a character from a string in C++. Table of Contents Remove a Character from String using std::remove() and string::erase() Remove a Character from String using std::erase() in C++ Remove a Character from String using Regex Remove a Character from String using std::remove() …

How to Remove a Character from String in C++ Read More »

Scroll to Top