Wil*_*mKF 5 c++ boost capitalize stdstring
我有一个 std::string 并希望第一个字母大写,其余字母小写。
我可以这样做的一种方法是:
const std::string example("eXamPLe");
std::string capitalized = boost::to_lower_copy(example);
capitalized[0] = toupper(capitalized[0]);
Run Code Online (Sandbox Code Playgroud)
这将产生capitalized:
“例子”
但也许有更直接的方法来做到这一点?
如果字符串确实只是一个单词,std::string capitalized = boost::locale::to_title (example)应该这样做。否则,您所拥有的将非常紧凑。
编辑:刚刚注意到boost::python命名空间有一个str带有capitalize()方法的类,听起来它适用于多字字符串(假设你想要你所描述的而不是标题大小写)。然而,仅仅为了获得该功能而使用 python 字符串可能是一个坏主意。
| 归档时间: |
|
| 查看次数: |
4762 次 |
| 最近记录: |