相关疑难解决方法(0)

剥离C中前导和尾随空格的最佳算法

剥离C中的前导和尾随空格的最佳方法是什么?

c string trim

8
推荐指数
4
解决办法
3万
查看次数

从std :: string的开头和结尾删除数字

使用像std :: find()这样的算法函数会有更好的方法吗?

std::string s = "012X012Y012";

//After erasing the numbers from beginning and end; the end result should be X012Y

size_t index = s.find_first_not_of("0123456789");
string::iterator iter_end = s.begin();
advance(iter_end, index);
s.erase(s.begin(), iter_end);

//Now std::string should be X012Y012

size_t index = s.find_last_not_of("0123456789")+1;
string::iterator iter_start = s.begin();
advance(iter_start, index);
s.erase(iter_start, s.end());

//Finally, std::string should be X012Y
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
241
查看次数

标签 统计

c ×1

c++ ×1

string ×1

trim ×1