碧海潮生's profile碧海潮生的小屋PhotosBlogLists Tools Help

Blog


    October 07

    C语言专题——标准库<string.h>

    1 复制
     
    char* strcpy (char *s1, const char *s2);
    将字符串s2复制到s1指定的地址
     
    char* strncpy (char *s1, const char *s2, size_t len);
    void*  memcpy (void *s1, const void *s2, size_t len);
    将s2的前len个字符(字节)复制到s1中指定的地址, 不加'\0'
     
    void* memmove (void *s1, const void *s2, size_t len);
    当源单元和目的单元缓冲区交迭时使用
     
    size_t strxfrm (char *s1, const char *s1, size_t len);
    根据程序当前的区域选项, 将s2的前len个字符(字节)复制到s1中指定的地址, 不加'\0'
     

    2 连接
     
    char* strcat (char *s1, const char *s2);
    将字符串s2连接到s1尾部
     
    char* strncat (char *s1, const char *s2, size_t len);
    将字符串s2的前len个字符连接到s1尾部, 不加'\0'
     

    3 比较
     
    int strcmp (const char *s1, const char *s2);
    比较字符串s1和s2
     
    int strncmp (const char *s1, const char *s2, size_t len);
    int  memcmp (const void *s1, const void *s2, size_t len);
    对s1和s2的前len个字符(字节)作比较
     
    int strcoll (const char *s1, const char *s2);
    根据程序当前的区域选项中的LC_COLLATE, 比较字符串s1和s2
     

    4 查找
     
    char* strchr (const char *s, int ch);
    void* memchr (const void *s, int ch, size_t len);
    在s中查找给定字符(字节值)ch第一次出现的位置
     
    char* strrchr (const char *s, int ch);
    在串s中查找给定字符ch最后一次出现的位置, r表示从串尾开始
     
    char* strstr (const char *s1, const char *s2);
    在串s1中查找指定字符串s2第一次出现的位置
     
    size_t strspn (const char *s1, const char *s2);
    返回s1中第一个在s2中不存在的字符的索引(find_first_not_of)
     
    size_t strcspn (const char *s1, const char *s2);
    返回s1中第一个也在s2中存在的字符的索引(find_first_of)
     
    char* strpbrk (const char *s1, const char *s2);
    与strcspn类似, 区别是返回指针而不是索引
     
    char* strtok (char *s1, const char *s2);
    从串s1中分离出由串s2中指定的分界符分隔开的记号(token)
    第一次调用时s1为需分割的字串, 此后每次调用都将s1置为NULL,
    每次调用strtok返回一个记号, 直到返回NULL为止
     

    5 其他
     
    size_t strlen (const char *s);
    求字符串s的长度
     
    void* memset (void *s, int val, size_t len);
    将从s开始的len个字节置为val
     
    char* strerror (int errno);
    返回指向错误信息字符串的指针
     
    source: 《C & C++ Code Capsules》

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://jx-kingwei.spaces.live.com/blog/cns!F7A152EB74B9576E!734.trak
    Weblogs that reference this entry
    • None