How to convert std::string to lower case?

后端 未结 26 1706
旧时难觅i
旧时难觅i 2020-11-22 00:01

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

26条回答
  •  悲&欢浪女
    2020-11-22 00:37

    Is there an alternative which works 100% of the time?

    No

    There are several questions you need to ask yourself before choosing a lowercasing method.

    1. How is the string encoded? plain ASCII? UTF-8? some form of extended ASCII legacy encoding?
    2. What do you mean by lower case anyway? Case mapping rules vary between languages! Do you want something that is localised to the users locale? do you want something that behaves consistently on all systems your software runs on? Do you just want to lowercase ASCII characters and pass through everything else?
    3. What libraries are available?

    Once you have answers to those questions you can start looking for a soloution that fits your needs. There is no one size fits all that works for everyone everywhere!

提交回复
热议问题