1.常常忘记加string 头文件

2.size和length函数没有区别,length函数是为了增强可读性

3.substr函数  s.substr(a,b)表示从a开始后的b位

  s.substr();//返回s的全部内容
  s.substr(11);//从索引11往后的子串
  s.substr(5,6);//从索引5开始6个字符

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”);

       s.insert(1,str);
  s.erase(13);//从索引13开始往后全删除
  s.erase(7,5);//从索引7开始往后删5个
6.关于find函数
  

  int find(char c, int pos = 0) const;//从pos开始查找字符c在当前字符串的位置
    int find(const char *s, int pos = 0) const;//从pos开始查找字符串s在当前串中的位置

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相似,只不过是从后向前查找

关于String函数的更多相关文章

  1. Python 常用string函数

    Python 常用string函数 字符串中字符大小写的变换 1. str.lower()   //小写>>> 'SkatE'.lower()'skate' 2. str.upper ...

  2. string函数分析

    string函数分析string函数包含在string.c文件中,经常被C文件使用.1. strcpy函数原型: char* strcpy(char* str1,char* str2);函数功能: 把 ...

  3. PHP String 函数

    [http://www.w3school.com.cn/php/php_ref_string.asp ] PHP String 简介 String 字符串函数允许您对字符串进行操作. 安装 Strin ...

  4. lua string函数

    lua的string函数: 参数中的index从1开始,负数的意义是从后开始往前数,比如-1代表最后一个字母 对于string类型的值,可以使用OO的方式处理,如string.byte(s.i)可以被 ...

  5. PHP 5 String 函数

    PHP 5 String 函数 PHP String 函数是 PHP 核心的组成部分.无需安装即可使用这些函数. 函数 描述 addcslashes() 返回在指定的字符前添加反斜杠的字符串. add ...

  6. c++string函数详解

    string,一个极为好用了函数,学好了这些函数,在模拟以及字符串问题上,回节省很多很多的写代码时间,代码复杂度以及错误率,那么这一类函数都有那些功能呢?我们来逐一介绍(让你大吃一惊,还有这种操作?) ...

  7. 常用string函数分析

    string函数分析string函数包含在string.c文件中,经常被C文件使用.1. strcpy函数原型: char* strcpy(char* str1,char* str2);函数功能: 把 ...

  8. c++:string函数

    string类的构造函数:string(const char *s);    //用c字符串s初始化string(int n,char c);     //用n个字符c初始化此外,string类还支持 ...

  9. C string 函数大全

    PS:本文包含了大部分strings函数的说明,并附带举例说明.本来想自己整理一下的,发现已经有前辈整理过了,就转了过来.修改了原文一些源码的问题,主要是用char *字义字符串的问题,导致程序运行时 ...

  10. C++string函数之strcat_s

    跟上一篇的strcpy_s一样,是新推出的较为安全的strcat函数 strcat_s脱胎于strcat,用于两个字符串的链接,strcat(str1,str2)直接返回新的str1. 但在vs200 ...

随机推荐

  1. day2_作业1(购物车)

    #!/usr/local/bin/python3 # -*- coding:utf-8 -*- balance=input("\033[36;1mPlease input your sala ...

  2. python爬虫:利用正则表达式爬取豆瓣读书首页的book

    1.问题描述: 爬取豆瓣读书首页的图书的名称.链接.作者.出版日期,并将爬取的数据存储到Excel表格Douban_I.xlsx中 2.思路分析: 发送请求--获取数据--解析数据--存储数据 1.目 ...

  3. HDU 6386 Age of Moyu

    Problem Description Mr.Quin love fishes so much and Mr.Quin’s city has a nautical system,consisiting ...

  4. C#学习你需要知道的---(For和Foreach)

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/52577283 作者:car ...

  5. getprop 与 dumpsys 命令

    Android 设备连接 PC 后,我们可以通过 adb 命令完成绝大多数工作.下面借助 getprop.dumpsys 来了解一些系统相关信息. 一.getprop 此命令的原理很简单,就是从系统的 ...

  6. adb 显示手机分辨率

    adb shell dumpsys window | grep "ShownFrame" | head -n 1 adb shell dwm size 当然,作为一个Android ...

  7. sql server inser相关处理(添加一条,一次添加多条,Bulk插入多条)

    1,insert语句 insert into 表一(字段一,字段二,字段三) value(值一,值二,值三) 2,sql 插入多条语句,其中完整值之间用逗号分割 insert into 表一(字段一, ...

  8. 《数据结构与算法分析:C语言描述》复习——第九章“图论”——拓扑排序

    2014.07.04 17:23 简介: 我们考虑一种特殊的图: 1. 有向图 2. 只有一个连通分量 3. 不存在环 那么这样的图里,必然可以找到一种排序方式,来确定谁在谁的“前面”. 简单的来说可 ...

  9. WordCount 基础功能

    软测第一次作业 该项目在码云上的地址: https://gitee.com/zhege/WordCount 一,概述 WordCount的基础功能需求分析大致如下:对程序设计语言源文件统计字符数.单词 ...

  10. Java基本-2对象与包

    1.对象:通俗的来讲,就是一个东西,比如汽车是一个对象,人是一个对象,狗是一个对象. 2.类:她描述的是对象的行为或者状态,比如对象是汽车,那么嘞可以分为小汽车类,大货车类,客车类等. 在类中可以包含 ...