Linked Questions
52 questions linked to/from Replace part of a string with another string
-2 votes
2 answers
962 views
C++: Replace character in a string with more than one number? [duplicate]
I am currently trying to replace a single character in a string with more than one number. Lets make it quick: replace(string.begin(), string.end(), 'a', '1'); ^ WORKS! ^ replace(string.begin(), ...
0 votes
1 answer
425 views
How to replace all occurrences of a character with a given string [duplicate]
I want to replace all occurrences of '$' with "$$". Currently I am using string::find to check if '$' is present in string or not. then I am using for loop and checking every character if it matches ...
0 votes
2 answers
161 views
c++ aut replace text row of character string [duplicate]
I found a little mistake, when I enter my email, find results that do not match expectations and the result is a symbol '@' turned into '%40', I would like to change the text '%40' became a symbol of ...
-3 votes
1 answer
171 views
Find sequence of chars in string c++ and erase it [duplicate]
I need find all occurrences of sequence: \r\n(some hex number)\r\n and delete this sequences from my string. Hexadecimal number doesn't start with 0x or x. It's just 20bb for example. These ...
-5 votes
2 answers
138 views
Erase all occurences of a word from a string [duplicate]
I have a string such as: AAAbbbbbAAA I'd like to remove all the occurances of a pattern AAA to get: bbbbb The pattern can occur anywhere in the string.
0 votes
0 answers
134 views
C++ replace all substrings in string [duplicate]
I apologize if this already has been answered but I didn't manage to find a solution on exactly this. I want to find all occurrences of a specific substring in a string and then replace those ...
1 vote
1 answer
94 views
Why does the replica work replace in c++? [duplicate]
I started learning C ++ and my task is to replace some characters in the text. Something similar to the template Here are some examples: <h1>Title</h1>$ js $<p>text...</p> ...
0 votes
0 answers
101 views
C++ String.Replace - no overloaded function takes 2 arguments? [duplicate]
I am trying to write a program that compresses text. For example, it would change aaaa to a^4. For whatever reason, my compiler thinks that I am trying to overload a function when I am not. Here is ...
0 votes
1 answer
82 views
How to replace a value in a string with another in c++? [duplicate]
if I have a string eg 2,4,-1,3,-1, how do I replace all the -1's with the word "wrong"? and how do I remove the comma at the very end? the output has come from an array cout<<array[c]<<"...
0 votes
0 answers
57 views
Replace a string in a vector of structs C++ [duplicate]
I am trying to replace a string in a vector of structs. struct Song { string artist; string title; string album; double m_price; string year; size_t length; }; vector<Song&...
0 votes
0 answers
57 views
replace 2 characters with 3 three in a string [duplicate]
I'm trying to replace "\n" with "\n" but I'm not allowed to do it with this function: std::replace(encryptedKey.begin(), encryptedKey.end(), "\n", "\\n"); encryptedKey is a long string. I think I ...
0 votes
1 answer
60 views
How to remove the token `[None]` from the album field of the songs and replace None with whitespaces? [duplicate]
The function: void cleanAlbum() removes the token [None] from the album field of the songs that do not have a valid album. I have a vector of Songs called collection and there are strings like string ...
146 votes
21 answers
293k views
Replace substring with another substring C++
How could I replace a substring in a string with another substring in C++, what functions could I use? eg: string test = "abc def abc def"; test.replace("abc", "hij").replace("def", "klm"); //...
274 votes
8 answers
151k views
How should I pass objects to functions?
I am new to C++ programming, but I have experience in Java. I need guidance on how to pass objects to functions in C++. Do I need to pass pointers, references, or non-pointer and non-reference values?...
125 votes
20 answers
397k views
What function is to replace a substring from a string in C?
Given a (char *) string, I want to find all occurrences of a substring and replace them with an alternate string. I do not see any simple function that achieves this in <string.h>.