C++ 如何从string中删除一个字符?
2014-09-12 20:45
274 查看
#include #include #include #include using namespace std;int main(){ string str = "abcdfccccefg"; string::iterator new_end = remove_if(str.begin(), str.end(), bind2nd(equal_to(), 'c')); str.erase(new_end, str.end()); cout << str << endl;string abc = "123'''''456";
int nPos = abc.find_first_of( '\'' ); if ( nPos != string::npos ) { abc = abc.substr( 0 , nPos ) + abc.substr( nPos + 1 , -1 ); } //else // break;cout<<abc; return 0;}
int nPos = abc.find_first_of( '\'' ); if ( nPos != string::npos ) { abc = abc.substr( 0 , nPos ) + abc.substr( nPos + 1 , -1 ); } //else // break;cout<<abc; return 0;}
相关文章推荐
- C++:如何删除string对象的末尾非数字字符
- C++ 一个问题:每次读取一个字符存入一个string中,最少读取100个字符,应该如何提高程序的性能?(C++ Primer 9.37 习题)
- C 如何从string中删除一个字符
- C++:如何删除string对象的末尾非数字字符
- 给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串。如何删除才能使得回文串最长呢? 输出需要删除的字符个数。
- java如何修改String其中一个字符
- [c++]string中删除相同字符
- C++删除字符串中特定一个或多个字符
- java如何修改String中的一个字符
- 给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串。如何删除才能使得回文串最长呢?
- 给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串。如何删除才能使得回文串最长呢? 输出需要删除的字符个数。
- c++如何取出string中的第一个字符…
- Java-基础 String操作删除字符串中的一个字符(字符串切割)
- C++实现的 如何删除一个指定的文件
- 如何判断一个String字符是否在string[]数组里
- C++如何判断一个string字符串,是否是数字
- C++从string中删除所有的某个特定字符
- C++中,如何执行一个控制台命令并返回结果到字符串string中
- 由string删除某个字符的操作发现的一个问题
- C++删除string最后一个字符的几种方法