注意是去掉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);
}
本文介绍了一个通用的字符串处理模板类BinaryDecisionTree中的三个成员函数:LeftTrimString, RightTrimString和TrimString。这些函数用于从给定的源字符串两端去除指定的字符集。通过模板实现,使得这些函数能够应用于多种不同的字符串类型。
985

被折叠的 条评论
为什么被折叠?



