std::string 各种操作
来源:互联网 发布:php arrayaccess 编辑:程序博客网 时间:2024/05/16 03:57
#include <string>
std::string str_strtest="username=123@qq.com&password=123123"; std::cout <<"str_strtest.back():111 " << str_strtest.back() <<std::endl; std::size_t found_name = str_strtest.find("username="); std::size_t found_and = str_strtest.find("&"); std::size_t found_password = str_strtest.find("password="); if(found_name!=std::string::npos) { std::cout <<"found_name: " << found_name <<std::endl; } if(found_and!=std::string::npos) { std::cout <<"found_and: " << found_and <<std::endl; } if(found_password!=std::string::npos) { std::cout <<"found_password: " << found_password <<std::endl; } std::string str_myusername, str_mypassword; str_myusername.assign(str_strtest,found_name+9,found_and-9); std::cout << "str_myusername: " << str_myusername << std::endl; std::cout <<"str_strtest.back():222 " << str_strtest.back() <<std::endl; str_mypassword.assign(str_strtest,found_and+10,str_strtest.back()); std::cout << "str_mypassword: " << str_mypassword << std::endl;// if(iter !=std::string::npos)// {// std::cout << " str_strtest iter: " << iter << std::endl;// str_strtest.replace(str_strtest.find("weifuliang"),10,"sucuihuang_hahhah");// std::cout << "str_strtest : " << str_strtest << std::endl;// }// std::string str("There are two needles in this haystack with needles.");// std::string str2("needle");// // different member versions of find in the same order as above:// std::size_t found = str.find(str2);// if (found != std::string::npos)// std::cout << "first 'needle' found at: " << found << '\n';// found = str.find("needles are small", found + 1, 6);// if (found != std::string::npos)// std::cout << "second 'needle' found at: " << found << '\n';// found = str.find("haystack");// if (found != std::string::npos)// std::cout << "'haystack' also found at: " << found << '\n';// found = str.find('.');// if (found != std::string::npos)// std::cout << "Period found at: " << found << '\n';// // let's replace the first needle:// str.replace(str.find("needles"), str2.length(), "preposition 123123123122312231123"); //replace 用法// std::cout << str << '\n';
阅读全文
0 0
- std::string 各种操作
- std:string = 赋值操作
- c++文件操作std::ifstream std::string::find() 和 std::string::npos
- C++ 对std::string 做 sizeof 操作
- std::string 类操作函数说明
- std::string类的常用操作
- String类的各种操作
- std::string
- std::string
- std::string
- std::string
- std::string
- std::string
- std::string
- std::string
- std::string
- std - string
- std::string
- 做到这几步,网红?你也可以
- Android学习笔记 一级二级菜单的使用
- 创建型模式—单例模式
- HDU 4300 Clairewd’s message (KMP)
- jvm的组成以及jvm的GC 垃圾回收算法分析
- std::string 各种操作
- 首看
- GitHub 上一份很受欢迎的前端代码优化指南
- Javascript模块化编程(二):AMD规范
- trokuti 三角形
- matplotlib绘制饼图函数pie的python脚本
- wampserver(php+apache+mysql) 服务器部署
- Ubuntu系统中安装配置Tomcat服务器
- poj1094 Sorting It All Out 拓扑排序 有向图判环 vector 模拟