Reputation: 7
I'm trying to replace any capitals as well as lengthening any contractions used in a string. I'm trying to find the fastest and most efficient approach.
Here is my attempt, which is not working:
Note: ur
is the 'unrefined input'
//Removing Capitals
std::transform(ur.begin(), ur.end(), ur.begin(), ::tolower);
//Removing Contractions
std::replace( ur.begin(), ur.end(), "it's", "it is");
Here is what's included in the program
#include <iostream>
#include <string>
#include <algorithm>
Upvotes: 0
Views: 89
Reputation: 7962
Your post contains two different questions, both of which are duplicates, and you are not saying what "is not working".
Removing capitals
The way you are writing it is correct if you are using ASCII characters only. See this answer for more details about supporting locales and other encodings.
Replacing contractions
This is very hard if you want it to be efficient.
If you just want to replace each contraction one by one, you shouldn't use replace
(it will only replace characters, not substrings). Have a look at this answer.
Upvotes: 1