技术小记2(string操作)

来源:互联网 发布:淘宝网男士羽绒背心 编辑:程序博客网 时间:2024/05/21 17:36

std::string

sring::substr(begpos);
string::find(begpos, ch);

std::string::size_type beg = url.find( "http://" );


_string_replace( std::string source, const char* old, const char* dest )
{
while( ( index = source.find( old ) ) != std::string::npos )
{
source.replace( index, strlen(old), dest );
}

}


void tstring_trim_left(std::wstring &str, char rmchar)
{
const TCHAR *psz = str.c_str();


while( rmchar == *psz )
{
psz++;
}


str = psz;
}




void tstring_trim_right(std::wstring &str, char rmchar)
{
const TCHAR *psz = str.c_str();
const TCHAR *pszLast = NULL;


while( *psz++ != 0 )
{
if( *psz == rmchar )
{
if( pszLast == NULL )
{
pszLast = psz;
}
}
else
{
pszLast = NULL;
}
}

str =  str.substr(0, pszLast - str.c_str());
}


void tstring_trim(std::wstring &str)
{
std::wstring::size_type pos = str.find_last_not_of(' ');
if(pos != std::wstring::npos)
{
str.erase(pos + 1);
pos = str.find_first_not_of(' ');
if(pos != std::wstring::npos) 
{
str.erase(0, pos);
}
}
else
{
str.erase(str.begin(), str.end());
}
}



原创粉丝点击