Python/C++ 对字符串的操作

字符串操作在任何语言中都很常用。 本文列举了一些常见的Python/c++ 对字符串的操作。 c++ 的使用了boost libraray,  所涉及到的函数都在  <boost/algorithm/string.hpp> 中定义。

  python  c++
大小写转换 'str'.upper(),  'str'.lower() boost::to_upper('str'), boost::to_upper_copy('str')
字符串包含某个substr str.find(substr) != -1 boost::contains(str, substr), boost::icontains(str, substr)
用给定字符串去连接字符串列表 'c'.join(list) boost::join(list), boost::join_if(list, pred)
以substr 开头或者结尾 str'.startswith(substr),  'str'.endswith(substr) boost::startswith(str, substr), boost::endswith(str, substr), boost::istartswith/boost::iendswith
左/右去除字符 str.strip() boost::trim_left/right_copy[_if]

posted @ 2015-01-06 22:28  zhifan  阅读(845)  评论(0)    收藏  举报