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

边栏推荐
猜你喜欢
随机推荐
传奇版本添加npc修改增加npc方法以及配置参数教程
WPF 截图控件之绘制方框与椭圆(四) 「仿微信」
DAY 22 丨 page daily clock in SQL 】 【 recommend 【 difficulty moderate 】
mongo根据时间字段进行时间格式化并进行统计
一口气说出4种主流数据库ID自增长,面试官懵了
JVM内存模型如何分配的?
piglit_get_gl_enum_name 参数遍历
es6箭头函数讲解
金仓数据库 KingbaseES 客户端编程接口指南 - ODBC 驱动使用
WordPress 常规设置
什么是DOM
mysql5.7.35安装配置教程【超级详细安装教程】
es6 arrow function explanation
Bookkeeping APP: Xiaoha Bookkeeping 3 - Production of Login Page
[纯理论] FCOS
拦截器与过滤器(三)@interface自定义注解拦截
[Cloud native] Introduction and use of Feign of microservices
JS_删除数组里的无效数据 0 undefined ‘‘ null false NaN
2022 IDEA (学生邮箱认证)安装使用教程以及基础配置教程
金仓数据库KingbaseES客户端编程接口指南-JDBC(3. JDBC 建立/关闭连接)









