C++ string 类型提取字符串
在某些情况下需要对输入的字符串进行处理,提取其中的需要的信息.
比如在linux中输入”mkdir test”,新建test文件夹,就需要提取其中的test字符.
提取的方法需要boost库中的函数,提取代码如下:
#include <string>
#include <iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
using namespace std;
int main(){
vector<string> itemlist;
vector<string> contentlist;
string strinfo="name#wangkaixuan$id#111$password#222";
boost::split(itemlist, strinfo, boost::is_any_of("$"));
for (int i = 0; i < itemlist.size(); ++i)
{
cout<<"strlist_"<<i<<"="<<itemlist[i]<<endl;
temp= itemlist[i];
boost::split(contentlist, temp, boost::is_any_of("#"));
cout<<"contentlist_0"<<"="<<contentlist[0]<<endl;
cout<<"contentlist_1"<<"="<<contentlist[1]<<endl;
}
return 0;
}
运行结果:iuc@iuc-linux ~/Project/CodeLibrares $ g++ string_find.cpp -o string_find
iuc@iuc-linux ~/Project/CodeLibrares $ ./string_find
strlist_0=name#wangkaixuan
contentlist_0=name
contentlist_1=wangkaixuan
strlist_1=id#111
contentlist_0=id
contentlist_1=111
strlist_2=password#222
contentlist_0=password
contentlist_1=222
iuc@iuc-linux ~/Project/CodeLibrares $
C++ string 类型提取字符串的更多相关文章
- delphi中如何将string类型的字符串数据转化成byte[]字节数组类型的数据
var S:String; P:PChar; B:array of Byte;begin S:='Hello'; SetLength(B,Length(S)+1); P:=PChar(S) ...
- 将String类型的字符串拼接成以逗号分隔的字符输出
package test; import java.util.ArrayList; import java.util.List; public class Tesdssss { private sta ...
- String类型 堆/字符串池的理解
1 package test; 2 3 public class StringTest { 4 5 public static void main(String[] args) { 6 7 /** 8 ...
- C++的string类型和继承C语言风格的字符串的区别与注意事项
1.尽可能地在C++程序中使用string,不要使用继承而来的C语言风格的字符串,会出现许多安全问题. 2.C语言的字符串风格,是以空字符结束的,在C++的头文件cstring中定义了C语言风格的字符 ...
- C++标准库string类型
string类型支持长度可变的字符串,C++标准库将负责管理与存储字符相关的内存,以及提供各种有用的操作.标准库string类型的目的就是满足对字符串的一般应用. 本文地址:http://www.cn ...
- 5.6.3 String类型
String类型是字符串的对象包装类型,可以像下面这样使用String构造函数来创建. var stringObject = new String("hello world"); ...
- C++标准库string类型的使用和操作总结
string是C++标准库最重要的类型之一,string支持长度可变的字符串,其包含在string头文件中.本文摘自<C++PRIMER 第四版·特别版>和个人的一些总结. 一.声明和初始 ...
- 获取的是 string 类型的字段,直接输出 数字 或者 需要的第几行
Freight = driver.find_element_by_xpath("//tbody/tr/td[6]").text print(type(Freight)) # 这里输 ...
- c++ string类型的定义及方法
1.c++ 有两种风格的字符串形式 c风格字符串 定义及初始化 char a[]={'h','e','l','l','o','\0'} 或者 char a[]="hello&quo ...
随机推荐
- std::ostringstream 转std::string
http://www.cplusplus.com/reference/sstream/ostringstream/ https://en.cppreference.com/w/cpp/io/basic ...
- fragment getActivity()空指针
Fragment弹出toast,时不时出现getActivity()空指针,具体原因未查到. 解决办法: if (null == fragment || !fragment.isAdded()) { ...
- Linux C/C++时间字符串与time_t之间的转换方法(转)
1.指定time_t类型的时间,格式化为YYYYMMDDHH24MISS型的字符串 void FormatTime(time_t time1, char *szTime) { struc ...
- 滴滴Booster移动APP质量优化框架 学习之旅 二
推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) 续写滴滴Booster移动APP质量优化框架学习之旅,上篇文章分 ...
- ASP.NET in C#,ClientScript.RegisterStartupScript与ClientScript.RegisterClientScriptBlock用法之己见
ClientScript.RegisterStartupScript:http://msdn.microsoft.com/zh-cn/library/system.web.ui.clientscrip ...
- Open-source Tutorial - Json.NET
JSON 简介 JSON(JavaScript Object Notation,JavaScript对象表示法)是一种由道格拉斯·克罗克福特构想和设计.轻量级的数据交换语言,该语言以易于让人阅读的文字 ...
- ncnn添加自己的layer
ncnn 是tencent公司开源的神经网络前向计算框架,github地址: https://github.com/Tencent/ncnn 通过简单的步骤可以添加自己的layer, 比如用位运算实现 ...
- css样式也技巧
目录 关于iPhone的点击事件绑定无效的处理方法 https://blog.csdn.net/u014477038/article/details/52527194 去掉a.button.input ...
- 手动配置webpack之React
安装 1.安装react转译相关依赖包: npm安装: npm install --save-dev babel-core babel-loader babel-preset- ...
- Unity手游引擎安全解析及实践
近日,由Unity主办的"Unity技术开放日"在广州成功举办,网易移动安全技术专家卓辉作为特邀嘉宾同现场400名游戏开发者分享了网易在手游安全所积累的经验.当下,很多手游背后都存 ...