删除string首尾以及中间的空格
对char*字符串进行操作,删除其中的空格,十分的繁琐。若代码为c++代码可以借助标准库算法,可对字符串首尾以及中间的空格进行删除。
#include <iostream>
#include <algorithm>
#include <string>
int main() {
std::string content = " 11223 3344 ";
content.erase(remove(content.begin(), content.end(), ' '), content.end());
std::cout << content << std::endl;
}
// output: 112233344
参考
[1] https://www.codeleading.com/article/92262643209/
[2] https://www.cnblogs.com/alexYuin/p/11546159.html