您的位置:首页 > 编程语言 > C语言/C++

C++学习:去掉字符串的首尾指定字符

2016-09-10 16:25 363 查看
注意是去掉strDrop中包含的所有字符。

template<typename StrType>
inline StrType BinaryDecisionTree::LeftTrimString(const StrType& strSource, const StrType& strDrop)
{
StrType strDstString(strSource);
return strDstString.erase(0, strDstString.find_first_not_of(strDrop));
}

template<typename StrType>
inline StrType BinaryDecisionTree::RightTrimString(const StrType& strSource, const StrType& strDrop)
{
StrType strDstString(strSource);
return strDstString.erase(strDstString.find_last_not_of(strDrop) + 1);
}

template<typename StrType>
inline StrType BinaryDecisionTree::TrimString(const StrType& strSource, const StrType& strDrop)
{
return LeftTrimString(RightTrimString(strSource, strDrop), strDrop);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: