- /*字符串长度函数*/
- size_t strlen(const char *string);
-
- /*不受限制的字符串函数*/
- char *strcpy(char *dst, const char *src);
- char *strcat(char *dst, const char *src);
- int strcmp(const char *s1, const char *s2);
-
- /*长度受限的字符串函数*/
- char *strncpy(char *dst, const char *src, size_t len);
- char *strncat(char *dst, const char *src, size_t len);
- int strncmp(const char *s1, const char *s2, size_t len);
-
- /*字符串查找*/
- /*
- * 功能:查找字符串s中首次出现字符c的位置
- * 说明:返回首次出现c的位置的指针,如果s中不存在c则返回NULL。
- */
- char *strchr(const char *str, int ch);
- //功能:查找字符串s中最后一次出现字符c的位置
* 说明:返回最后一次出现c的位置的指针,如果s中不存在c则返回NULL。
- char *strrchr(const char *str, int ch);
-
- /*
- * 功能:依次检验字符串str中的字符,当被检验字符在字符串group中也包含时,则停止检验,并返回该字 * 符位置,空字符NULL不包括在内。
- * 说明:返回str中第一个满足条件的字符的指针,如果没有匹配字符则返回空指针NULL。
- */
- char *strpbrk(const char *str, const char *group);
-
- /*
- * 功能:找出str2字符串在str1字符串中第一次出现的位置(不包括str2的串结束符)。
- * 返回值:返回该位置的指针,如找不到,返回空指针。
- */
- char *strstr(const char *str1, const char *str2);
-
-
- /*
- * 功能:分解字符串为一组字符串。s为要分解的字符串,delim为分隔符字符串。
- * 说明:strtok()用来将字符串分割成一个个片段。参数s指向欲分割的字符串,参数delim则为分割字符串 * ,当strtok()
- * 在参数s的字符串中发现到参数delim的分割字符时则会将该字符改为\0 字符。在第一次调用时,strtok( * )必需给予参数
- * s字符串,往后的调用则将参数s设置成NULL。每次调用成功则返回被分割出片段的指针。
- * 返回值:从s开头开始的一个个被分割的串。当没有被分割的串时则返回NULL。所有delim中包含的字符都 * 会被滤掉,并将
- * 被滤掉的地方设为一处分割的节点。
- */
- char *strtok(char *s, const char *delim);
-
-
-
- /*第一次出现的起始位置*/
- /*
- * 函数说明 strspn()从参数str 字符串的开头计算连续的字符,而这些字符都完全是group 所指字符串中 * 的字符。简单的说,
- * 若strspn()返回的数值为n,则代表字符串str 开头连续有n 个字符都是属于字符串group内的字符。
- * 返回值 返回字符串str开头连续包含字符串group内的字符数目。
- */
- size_t strspn(const char *str, const char *group);
-
-
- /*
- * 功能:顺序在字符串str中搜寻与group中字符的第一个相同字符,返回这个字符在Str中第一次出现的位置
- * 说明:(返回第一个出现的字符在str中的下标值,亦即在str中出现而group中没有出现的子串的长度。)
- * 简单地说,若strcspn()返回的数值为n,则代表字符串str开头连续有n个字符都不含字符串group内的字符
- */
- size_t strcspn(const char *str, const char *group);
-
- /*大小写字符转换函数*/
- int tolower(int ch);
- int toupper(int ch);
- /*内存操作函数*/
- void *memcpy(void *dst, const void *src, size_t length);
- void *memmove(void *dst, const void *src, size_t length);
- void *memcmp(const void *a, const void *b, size_t length);
- void *memset(void *a, int ch, size_t length);
- strtok函数
-
原型:char *strtok(char *s, char *delim);
功能:分解字符串为一组标记串。s为要分解的字符串,delim为分隔符字符串。
说明:首次调用时,s必须指向要分解的字符串,随后调用要把s设成NULL。 strtok在s中查找包含在delim中的字符并用NULL('\0')来替换,直到找遍整个字符串。 返回指向下一个标记串。当没有标记串时则返回空字符NULL。
- #include <iostream>
- using namespace std;
- int main(int argc, char * argv[])
- {
- //时间格式 2010/08/11 10:38:22
- char strEventTime[] = "2010/08/11 10:38:22";
- char *token = NULL;
- token = strtok(strEventTime, "/");
- char *year = token;
- if (token != NULL)
- {
- token = strtok(NULL, "/");
- }
- char *month = token;
- if (token != NULL)
- {
- token = strtok(NULL, " ");
- }
- char *day = token;
- if (token != NULL)
- {
- token = strtok(NULL, ":");
- }
- char *hour = token;
- if (token != NULL)
- {
- token = strtok(NULL, ":");
- }
- char *minute = token;
- if (token != NULL)
- {
- token = strtok(NULL, ":");
- }
- char *second = token;
- printf("%s %s %s %s %s %s %s\n", year, month, day, hour, minute, second);
- return 0;
- }
- 原型:char *strdup(const char *s);
- The strdup function returns a pointer to a new string which is a duplicate of the string s.Memory for the new string is obtained with malloc,and can be freeed with free.
- strcspn函数
- 原型:size_t strcspn(const char *s,const char *reject);
- this function calculates the length of the initial segment of 's' which consists entirely of characters not in 'reject'.
- returns the number of characters in the initial segment of s which are not in the strings 'reject'
C语言常用的各种操作字符串的函数
最新推荐文章于 2021-08-07 10:07:03 发布