#include <iostream>
using namespace std;
//删除字符串右边的全部空格
char *my_trim( char *str )
{
if (NULL == str)
{
throw;
}
char *const address = str;
const int ONE_ELEMENT = 1;
const char NULL_TERMINATED = '\0';
while (NULL_TERMINATED != *str)
{
++str;
}
while (address != str && isspace( *(str - ONE_ELEMENT) ))
{
--str;
}
*str = NULL_TERMINATED;
str = address;
return str;
}
int main(int argc,char*argv[])
{
char buf[] = "ok2002.com ";
cout << strlen( buf ) << endl;
my_trim( buf );
cout << strlen( buf ) << endl;
system( "PAUSE" );
return EXIT_SUCCESS;
}
/*----
24
10
请按任意键继续. . .
-----------------------*/
删除字符串右边的全部空格
最新推荐文章于 2024-04-05 10:24:34 发布