0

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>
Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
  • Please, only one question each. Also, it may be interesting, but for the title it is completely irrelevant that you are trying to write a chatbot. However, what is relevent is e.g. the type of `ur` and the issues you have with your code. Please see https://stackoverflow.com/help/how-to-ask, your question as it stands is off-topic. – Ulrich Eckhardt Jul 13 '15 at 17:34

1 Answers1

1

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.

Community
  • 1
  • 1
Jonathan H
  • 7,591
  • 5
  • 47
  • 80