c++ STL string类的查找、替换和删除操作
2013-11-23 22:27
211 查看
#include "stdafx.h" #include <iostream> #include <string> using std::string; using std::cin; using std::cout; using std::endl; int _tmain(int argc, _TCHAR* argv[]) { string strContent = "www.jiesoon.com is a exciting site for all C/C++ developers! www.jiiesoon.cn is a sub-site in China."; //查找 string::size_type nPos = strContent.find("jiesoon", 0); //从0位置开始查找 if(nPos != string::npos){ cout << "find jeasoon on" << nPos << endl; } else{ cout << "Can't find jeasoon on offset 0" << endl; } //删除 strContent.erase(4, 7); cout << strContent << endl; //替换 strContent.replace(4, 7, "JIESOON"); cout << strContent << endl; getchar(); return 0; }
相关文章推荐
- 数据库访问及其基本操作(sql server和添加删除查找替换)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- python字符串操作,截取,拼接,替换,删除,比较,查找
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- shell文件操作(删除,显示,查找,增加,替换) sed用法
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 黄聪:Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 黄聪:Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)