字符串相关函数整理
按功能分类:
字符串连接:
strcat : char* strcat(char* destination, const char* source);
strncat : char* strcat(char* destination, const char* source, size_t num);
cat 意思是catenate。连接的意思。
strncp 是strcat的安全版本号。能够防止越界。
从定义上能够看出带是将const的字符串连接到不带const的字符串上。
字符/字符串查找:
strchr : char* strchr(const char* str, int character); char* strchr(char* str, int character);
查找字符character在str中第一次出现的位置。返回一个指针指向该字符到字符串结尾。
因为'\0'也是字符串的一部分,故该函数也能够查找结束符。
chr意思应该是character。
strrchr : char* strchr(const char* str, int character); char* strchr(char* str, int character);
最后一次出现的位置。
'r'应该是right的意思。也就是从右開始搜索。
strpbrk : const char* strpbrk(const char* str1,const char* str2); char* strpbrk(char* str1,const char* str2);
查找str2中随意字符在str1中第一次出现的位置,返回从整个位置到str1最后的字符串。
不包括结束符。
strcspn : size_t strcspn(const char* str1, const char* str2);
返回的是str1第一次出现str2中随意字符的位置。搜索包括null结束符,所以函数能够返回str1字符串的长度当没有不论什么匹配的时候。
strstr : const char* strstr(const char* str1, const char* str2); char* strstr(char* str1, const char* str2);
匹配完整字符串
字符串比較:
strcmp: int strcmp(const char* str1, const char* str2);
strncmp: int strcmp(const char* str1, const char* str2, size_t num);
strcoll: int strcoll(const char* str1, const char* str2);
依据LC_COLIATE比較str1和str2。
字符串拷贝:
strcpy : char* strcpy(char* destination, const char* source);
strncpy : char* strcpy(char* destination, const char* source, size_t num);
拷贝source到destination中去。遇到'\0'停止copy。
获取字符串长度:
strlen: size_t strlen(const char* str);
拆分字符串:
strtok: char* strtok(char* str, const char* delimiters);
tok的意思是token。该函数就是将str依据delimiter拆分。
相关文章
- 3.PHP条件语句及其字符串相关函数
- Python join() 函数 连接字符串
- Python repr() 函数用法及实例(各种类型转字符串)
- 浮点数转成字符串函数gcvt()
- python中any()函数用法详解
- 第三十九章 SQL函数 DATABASE
- 第二十八章 Caché 函数大全 $LISTDATA 函数
- Oracle数据库:oracle函数,单行函数,多行函数,upper,lower,initcap,字符串函数
- algorithm头文件下的常用函数--习题
- 码栈开发手册(四)---编码方式开发(字符串处理相关函数)
- [转]理解Vuex的辅助函数mapState, mapActions, mapMutations用法
- 一篇文章把你带入到JavaScript中的闭包与高级函数
- 多态基类的析构函数应该为虚函数
- Perl函数:字符串相关函数
- 面向过程编程的致命缺陷是算法与算法的结合方式过于单一,面向对象和函数式编程都是对这一缺陷的改进
- 用一个函数来实现将一行字符串中最长的单词输出。此行字符串从主函数传递给该函数。
- mysql截取字符串与reverse函数
- SQL Server 中截取字符串常用的函数
- mysql 函数substring_index() 截取字符串
- python字符串函数
- 关于pow()函数的小知识
- 四、Matlab 之 常见函数的使用
- 字符串常用函数
- SQL字符串函数
- PHP调试函数
- 练习 3-2 编写一个函数escape(s, t),将字符串t复制到字符串s中,并在复制过程中将换行符、制表符等不可见字符分别转换为n、t等相应的可见的转义字符序列。要求使用switch语句。
- 练习 2-5 编写函数 any(s1, s2),将字符串s2中的任一字符在字符串s1中第一次出现的位置作为结果返回。如果s1中不包含s2中的字符,则返回-1。
- 【MySQL】MySQL 8.0 新特性之 - 窗口函数(Window Functions)