去除字符串空格
#include <iostream>
#include <cstring>
using namespace std;//遍歷元字符串,刪除空格
char *remove_blank(char *str)
{int index = 0;for(int ii=0;ii<strlen(str);ii++){if(str[ii] != ' '){str[index++] = str[ii];} }str[index] = '\0';return str;
}int main(){char s1[]=" 1 2 34 5 ";cout<<remove_blank(s1)<<endl;
}
總結
- 上一篇: 拆分字符串使唯一子字符串的数目最大
- 下一篇: 不修改数组找出重复的数字