关于String函数
1.常常忘记加string 头文件
2.size和length函数没有区别,length函数是为了增强可读性
3.substr函数 s.substr(a,b)表示从a开始后的b位
4.关于append函数和assign函数,append函数更偏向于添加,而assign更偏向于赋值。
s.append(5,'x')添加5个x;s.append(str,1,5)把str的1到5添加给s;
5.关于insert、erase函数
s.insert(0,”my name”);
int find(const char *s, int pos, int n) const;//从pos开始查找字符串s中前n个字符在当前串中的位置
int find(const string &s, int pos = 0) const;//从pos开始查找字符串s在当前串中的位置
//查找成功时返回所在位置,失败返回string::npos的值
int rfind(char c, int pos = npos) const;//从pos开始从后向前查找字符c在当前串中的位置
int rfind(const char *s, int pos = npos) const;
int rfind(const char *s, int pos, int n = npos) const;
int rfind(const string &s,int pos = npos) const;
//从pos开始从后向前查找字符串s中前n个字符组成的字符串在当前串中的位置,成功返回所在位置,失败时返回string::npos的值
int find_first_of(char c, int pos = 0) const;//从pos开始查找字符c第一次出现的位置
int find_first_of(const char *s, int pos = 0) const;
int find_first_of(const char *s, int pos, int n) const;
int find_first_of(const string &s,int pos = 0) const;
//从pos开始查找当前串中第一个在s的前n个字符组成的数组里的字符的位置。查找失败返回string::npos
int find_first_not_of(char c, int pos = 0) const;
int find_first_not_of(const char *s, int pos = 0) const;
int find_first_not_of(const char *s, int pos,int n) const;
int find_first_not_of(const string &s,int pos = 0) const;
//从当前串中查找第一个不在串s中的字符出现的位置,失败返回string::npos
int find_last_of(char c, int pos = npos) const;
int find_last_of(const char *s, int pos = npos) const;
int find_last_of(const char *s, int pos, int n = npos) const;
int find_last_of(const string &s,int pos = npos) const;
int find_last_not_of(char c, int pos = npos) const;
int find_last_not_of(const char *s, int pos = npos) const;
int find_last_not_of(const char *s, int pos, int n) const;
int find_last_not_of(const string &s,int pos = npos) const;
//find_last_of和find_last_not_of与find_first_of和find_first_not_of相似,只不过是从后向前查找
转载于:https://www.cnblogs.com/TYH-TYH/p/9425578.html
关于String函数相关推荐
- [Leetcode][第557题][JAVA][反转字符串中的单词 III][遍历][String函数]
[问题描述][简单] [解答思路] 1. 遍历 开辟一个新字符串.然后从头到尾遍历原字符串,直到找到空格为止,此时找到了一个单词,并能得到单词的起止位置.随后,根据单词的起止位置,可以将该单词逆序放到 ...
- stl string 函数_使用C ++ STL中的string :: append()函数将文本追加到字符串
stl string 函数 append() is a library function of <string> header, it is used to append the extr ...
- [开心学php100天]第五天:string函数(上)
注意:本文上午已经发布,由于排版问题特修改后重发. 本期格言: 越高级的技术越需要扎实的基本功.而学好基本功的首要条件是能沉住气和静下心. 往往很多程序员太想一口吃一个肥婆而直接略过基础部分去学习高 ...
- 前端中unescape是什么意思_详解JavaScript中的Unescape()和String() 函数
JavaScript中的Unescape()和String() 函数详解,具体内容如下所示: 定义和用法 JavaScript unescape() 函数可对通过 escape() 编码的字符串进行解 ...
- Matlab中string函数的使用
目录 创建对象 语法 示例 拆分字符串并查找唯一单词 转换字符向量 转换元胞数组 转换数值数组 转换表示数字的字符串 转换持续时间数组 从 R2016b 开始,可以使用字符串数组而不是字符数组来表示文 ...
- c++ string函数详细返回值及用法!
通过在网站上的资料搜集,得到了很多关于string类用法的文档,通过对这些资料的整理和加入一些自己的代码,就得出了一份比较完整的关于string类函数有哪些和怎样用的文档了! 下面先罗列出string ...
- Go string函数与strconv.Itoa函数的区别
Itoa函数 strconv.Itoa函数的参数是一个整型数字,它可以将数字转换成对应的字符串类型的数字. package mainimport ("fmt""strco ...
- Python - 爬虫 - Xpath定位之starts-with()和string()函数的简单使用
Python - 爬虫 - Xpath定位之starts-with()和string()函数的简单使用 文章目录 Python - 爬虫 - Xpath定位之starts-with()和string( ...
- java string()函数_从Java中的String函数返回String构建器?
我有以下程序,我必须将字符串附加到另一个字符串,我使用字符串构建器以标准方式执行.但是,即使在将其转换为toString()之后,该函数也不允许我返回ab.我想问为什么? import java.ut ...
- 30秒的PHP代码片段(3)字符串-String 函数-Function
本文来自GitHub开源项目 点我跳转 30秒的PHP代码片段 精选的有用PHP片段集合,您可以在30秒或更短的时间内理解这些片段. 字符串 endsWith 判断字符串是否以指定后缀结尾,如果以指定 ...
最新文章
- python逐行写入csv_python之模块csv之CSV文件的写入(按行写入)
- 洛谷P3884 二叉树问题
- [HDOJ2845]Beans(dp)
- html左侧td字体居右,如何在td中控制字体右对齐 且加粗_html/css_WEB-ITnose
- multisim怎么设置晶体管rbe_Multisim 10在单管共射放大电路中的应用
- CorelDraw技巧|设计师要了解数位板怎么用
- 分享9个实用的电脑维修技巧,赶紧收藏吧!
- 频谱分析幅值单位_案例分享丨某水泥厂入窑斗提减速机不对中故障分析及处理...
- c++中的继承--1(引出,继承方式,继承的对象模型)
- 一个七年程序员的经验
- 算法--最大连续子序列和(动态规划,分而治之)
- ORACLE取周、月、季、年的開始时间和结束时间
- CCF NOI1066 素数对
- UEFI win7系统的安装
- API RSA签名颁发证书
- C# Windows Phone App 开发,自制LockScreen 锁定画面类别(Class),从【网路图片】、【Assets资源】、【UI】修改锁定画面。...
- javawebday30(验证码在客户端 用当前时间来请求下一张图片 VerifyCode代码)
- 晨曦记账本记账收支,统计结余
- hdu 2167 Pebbles 状态压缩dp
- Android教程之如何使用自定义字体