//功能: 移动字符串中的"\r" "\n"
string StrClean(const string &strSource)
{
string strDes = strSource;
string::size_type index = 0;
do
{
index = strDes.find("\r");
if (index != string::npos)
{
strDes = strDes.erase(index, strlen("\r"));
}
else
{
index = strDes.find("\n");
if (index != string::npos)
{
strDes = strDes.erase(index, strlen("\r"));
}
}
} while (string::npos != index);
return strDes;
}
string StrClean(const string &strSource)
{
string strDes = strSource;
string::size_type index = 0;
do
{
index = strDes.find("\r");
if (index != string::npos)
{
strDes = strDes.erase(index, strlen("\r"));
}
else
{
index = strDes.find("\n");
if (index != string::npos)
{
strDes = strDes.erase(index, strlen("\r"));
}
}
} while (string::npos != index);
return strDes;
}
本文提供了一个函数,用于从输入字符串中删除所有换行符(
)和回车符(
)。通过遍历字符串并使用find和erase方法,该函数有效地清理了文本内容,使其更易于处理和显示。
8158

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



