void deleteBlank(char str[])
{
int len = strlen(str), i, j, p, s, e = len;
for(i = 0; i < len; ++i)
{
if(str[i] != ' ')continue;
if(str[i+1] == ' ') p = i+1;
for(j = i+1; j < len; ++j)
if(str[j] != ' ')break;
s = j; e = len;
for(j = s; j < len; ++j)
if(str[j]==' '){e = j; break;}
for(j = s; j < e; j++)
{str[p++] = str[j]; str[j] = ' ';}
if(j == len)
{str[p] = 0;break;}
i = p-1;
}
}
void deleteBlank2(char str[])
{
int len = strlen(str), i, j, p;
for(i = 0; i < len; ++i)
{
if(str[i] != ' ') continue;
if(str[i+1] == ' ') p = i + 1;
for(j = i+1; j < len; ++j) if(str[j] != ' ') break;
do{
str[p] = str[j];
str[j] = ' ';
p++;
j++;
}while(j < len && str[j] != ' ');
i = p - 1;
}
}
删除字符串多余空格
最新推荐文章于 2021-05-18 10:54:10 发布