当前位置:网站首页>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;
}

边栏推荐
- asyncawait和promise的区别
- JS_删除数组里的无效数据 0 undefined ‘‘ null false NaN
- mysql根据多字段分组——group by带两个或多个参数
- PD 源码分析- Checker: region 健康卫士
- 金仓数据库KingbaseES客户端编程接口指南-ODBC(8. 示例说明)
- 【c ++ primer 笔记】第6章 函数
- MLX90640 infrared thermal imaging temperature measuring sensor module development notes (9)
- [纯理论] FPN (Feature Pyramid Network)
- WPF 截图控件之绘制方框与椭圆(四) 「仿微信」
- Path dependence - accidental decision to rely on.
猜你喜欢
随机推荐
SQL clock in daily DAY 21 丨 】 each post comments difficulty moderate 】 【
TiCDC synchronization delay problem
[WeChat applet] WXSS and global, page configuration
MySQL database installation (detailed)
【实用工具】Image Assistant下载指定页面的所有图片
【云原生】-Docker容器迁移Oracle到MySQL
MySql字符串拆分实现split功能(字段分割转列、转行)
金仓数据库KingbaseES安全指南--6.7. GSSAPI身份验证
Draw boxes of WPF screenshots controls and ellipse (4) "imitation WeChat"
容器化 | 在 Rancher 中部署 MySQL 集群
MarkDown Advanced Syntax Manual
Mysql进阶优化篇01——四万字详解数据库性能分析工具(深入、全面、详细,收藏备用)
WordPress 重置密码
npm install 报错问题解决合集
IDEA 数据库插件Database Navigator 插件
nacos集群搭建
【多线程】——synchronized关键字
Windows系统Mysql8版本的安装教程
RedisTemplate使用详解
TiCDC迁移-TiDB到MySQL测试








