C++ string functions

C++ string functions(C++里面比较常用的STRING函数)

strings may be manipulated without using the standard library. However, the library contains many useful functions for working with both zero-terminated strings and unterminated arrays of char.

STRING(下面简称STR) 可以被使用在没有标准库的情况下.但是标准库包含了很多比较有用的函数,这些函数可能是可终结STR或者不可终结STR(比如ARRAY OF CHAR).  PS:事实上STR就是一个ARRAY,只是一个比较特殊一点的ARRAY而已.

The most commonly used string functions are:(常用STR函数)

以下描述中,SOURCE我表示的是源数据,DEST表示的是执行目标,DEST事实上我是简化了DESTINATION(英文中"目的地"的意思).希望大家能容易看懂我写的.

  • strcat(dest, source) - appends the string source to the end of string dest (挂起STR-SOURCE到STR-DEST的尾部)
  • strchr(s, c) - finds the first instance of character c in string s and returns a pointer to it or a null pointer if c is not found (在STR-S里面查找第一个字母C,找到以后回一个指针给它,如果没有找到就不回指针,呵呵,感觉后面是废话.)
  • strcmp(a, b) - compares strings a and b ;returns negative if a is less than b, 0 if equal, positive if greater. (比较STR-A和STR-B,如果A<B就显示负指,如果相等就显示0,A>B就显示正数)
  • strcpy(dest, source) - copies the string source to the string dest (复制SOURCE到DEST)
  • strlen(st) - return the length of string st (一个计算STR-ST长度的函数)
  • strncat(dest, source, n) - appends a maximum of n characters from the string source to the end of string dest; characters after the null terminator are not copied. (N代表一个数值,比如5,所以挂起最多5个字符到STR-DEST,这5个字母来自STR-SOURCE).
  • strncmp(a, b, n) - compares a maximum of n characters from strings a and b (lexical ordering); returns negative if a is less than b, 0 if equal, positive if greater. (和前面的比较函数STRCMP差不多,只是引进了数值N代表N个字符的比较(按字母顺序),比较以后返回数值和STRCMP一样,正数负数和0)
  • strncpy(dest, source, n) - copies a maximum of n characters from the string source to the string dest (和STRCPY类似,复制最多N个字母从SOURCE到DEST.)
  • strrchr(s, c) - finds the last instance of character c in string s and returns a pointer to it or a null pointer if c is not found (查找最后一个字母C在STR-S里面,返回指针规则和STRCHR函数一样)

The less common string functions are:(非常用STR函数)

  • strcoll(s1, s2) - compare two strings according to a locale-specific collating sequence
  • strcspn(s1, s2) - returns the index of the first character in s1 that matches any character in s2
  • strerror(err) - returns a string with an error message corresponding to the code in err
  • strpbrk(s1, s2) - returns a pointer to the first character in s1 that matches any character in s2 or a null pointer if not found
  • strspn(s1, s2) - returns the index of the first character in s1 that matches no character in s2
  • strstr(st, subst) - returns a pointer to the first occurrence of the string subst in st or a null pointer if no such substring exists.
  • strtok(s1, s2) - returns a pointer to a token within s1 delimited by the characters in s2.
  • strxfrm(s1, s2, n) - transforms s2 into s1 using locale-specific rules
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值