当前位置:网站首页>38.【string下章】
38.【string下章】
2022-07-29 12:28:00 【李在奋斗……】
1.提取函数 substr(始,末)
从第几个元素开始,往后数几个元素。
2.查找函数 find(字符串/字符,始)
查找哪个元素或字符串,从第几个开始。
3.替换函数 replac(始,末,字符串)
从第几个开始,往后数几个,换成谁。
4.插入函数 insert(始,字符串)
从第几个开始,插入谁。
5.插入函数 insert(始,末,字符)
从第几个开始,插入几个,插入谁。
6.删除函数 erase(始,末)
从第几个开始,删除几个。
======================
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string s1,s2,s4,s5,s6,s7,s8;
int s3;
s1 = "hello cctv.com byebye";
cout << "原数组为:" << s1 << endl;
s2=s1.substr(6, 8); // 从第几个开始,进行提取几个,
cout <<"通过数数得:"<< s2 << endl;
s3 = s1.find("cctv.com",0); // 找谁, 从第几个元素找
s4 = s1.substr(s3, 8);
cout <<"通过找到得:"<< s4 << endl;
s5 = s1.replace(0, 5, "李威涛"); //从第几个开始,前几个字符换成后面的
cout << "通过replace进行添加:" << s5 << endl;
s6 = s1.insert(0, "勇敢的"); //第几个开始 ,插入谁
cout << "通过插入进行添加:" << s6 << endl;
s7 = s1.insert(0, 3, 'v'); // 第几个开始,插入几个,插入谁
cout << "插入字符为:" << s7 << endl;
s1 = s1 + " 888";
cout << s1 << endl;
s8 = s1.erase(0, 5); //第几个开始, 删除几个
cout << "删除:" << s8 << endl;
}

边栏推荐
- TiCDC同步延迟问题处理
- 拦截器与过滤器(三)@interface自定义注解拦截
- IDEA 数据库插件Database Navigator 插件
- 我和 TiDB 的故事 | TiDB 对我不离不弃,我亦如此
- WordPress 重置密码
- Bika LIMS 开源LIMS集—— SENAITE的使用(用户、角色、部门)
- 2022-07-29 Daily: The latest major progress of AlphaFold: complete almost all known protein structure predictions of more than 200 million, fully open
- mysql5.7.35安装配置教程【超级详细安装教程】
- Interceptors and filters (3) @interface custom annotation interception
- MySql string splitting realizes the split function (field splitting, column switching, row switching)
猜你喜欢
随机推荐
栈“后进先出”和队列中“先进先出”的含义
网页被劫持跳转怎么办?发布网修复方法
[based] GO language. Why do I have to learn Golang and introduction to the language universal
mysql数据库安装(详细)
Wu En teacher machine learning course notes 6 logistic regression
js进阶四(map、reduce、filter、sort、箭头函数、class继承、yield)
国内首秀元宇宙Live House圆满收官,百事可乐虚拟偶像真的好会!!
金仓数据库KingbaseES客户端编程接口指南-JDBC(2. 概述)
TiDB 操作实践 -- 备份与恢复
QCon Guangzhou Station is here!Exclusive custom backpacks are waiting for you!
飞桨框架体验评测交流会,产品的使用体验由你来决定!
Paddle frame experience evaluation and exchange meeting, the use experience of the product is up to you!
Container is changed | deploy MySQL cluster in the Rancher
记账APP:小哈记账3——登录页面的制作
Chapter ten find and record the REST API
The adb for mysql in what platform for development
策略模式替代 if else
数组及其内存管理三问
WordPress 编辑用户
TiCDC synchronization delay problem








