I want to convert a std::string
to lowercase. I am aware of the function tolower()
, however in the past I have had issues with this function and it is hardly ideal anyway as use with a std::string
would require iterating over each character.
Is there an alternative which works 100% of the time?
Use fplus::to_lower_case().
(fplus: https://github.com/Dobiasd/FunctionalPlus.
Search 'to_lower_case' in http://www.editgym.com/fplus-api-search/)
From this:
You're really not going to get away with iterating through each character. There's no way to know whether the character is lowercase or uppercase otherwise.
If you really hate
tolower()
, here's a non-portable alternative that I don't recommend you use:Be aware that
::tolower()
can only do a per-single-byte-character substitution, which is ill-fitting for many scripts, especially if using a multi-byte-encoding like UTF-8.