C++

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 »

Scroll to Top