C++

Replace character in string at a particular index in C++

In this article, we will discuss different ways to replace a character in string at a particular index in C++. Table Of Contents Introduction Case 1: The index of the character to be replaced and the new character are given as input. Using std::string::replace() Using the [] operator Case 2: The character to be replaced …

Replace character in string at a particular index in C++ Read More »

Split String into Substrings of equal length in C++

In this artcile, we will discuss different ways to split a string into multiple substrings of equal lemnth in C++. Table Of Contents Introduction Method 1: Using substr() Method 2: Using iterators Summary Introduction There can be two variations for the given problem:1. The number of substrings is given and we need to calculate the …

Split String into Substrings of equal length in C++ Read More »

Count occurrences of a character in a string in C++

In this article, we will discuss different ways to count occurrences of a given character in a string in C++. Table Of Contents Method 1: Using std::count() Method 2: Using std::count_if() Method 3: Using std::find() Summary Method 1: Using std::count() The first approach, that we will learn is the standard template library algorithm std::count() function. …

Count occurrences of a character in a string in C++ Read More »

Scroll to Top