常用字串函式

2021-04-13 23:07:34 字數 3021 閱讀 8140

memset

原型:extern void *memset(void *buffer, int c, int count);

用法:#include

功能:把buffer所指記憶體區域的前count個位元組設定成字元c。

說明:返回指向buffer的指標。

舉例:// memset.c

#include

#include

main()

memcpy

原型:extern void *memcpy(void *dest, void *src, unsigned int count);

用法:#include

功能:由src所指記憶體區域複製count個位元組到dest所指記憶體區域。

說明:src和dest所指記憶體區域不能重疊,函式返回指向dest的指標。

舉例:

// memcpy.c

#include 

#include 

main()

strcpy

原型:extern char *strcpy(char *dest,char *src);

用法:#include

功能:把src所指由null結束的字串複製到dest所指的陣列中。

說明:src和dest所指記憶體區域不可以重疊且dest必須有足夠的空間來容納src的字串。返回指向dest的指標。

舉例:

// strcpy.c

#include 

#include 

main()

strcat

原型:extern char *strcat(char *dest,char *src);

用法:#include

功能:把src所指字串新增到dest結尾處(覆蓋dest結尾處的'/0')並新增'/0'。

說明:src和dest所指記憶體區域不可以重疊且dest必須有足夠的空間來容納src的字串。返回指向dest的指標。

舉例:

// strcat.c

#include 

#include 

main()

strcmp

原型:extern int strcmp(char *s1,char * s2);

用法:#include

功能:比較字串s1和s2。

說明:

當s1時,返回值<0

當s1=s2時,返回值=0

當s1>s2時,返回值》0

舉例:

// strcmp.c

#include 

#include 

main()

strlwr

原型:extern char *strlwr(char *s);

用法:#include

功能:將字串s轉換為小寫形式

說明:只轉換s中出現的大寫字母,不改變其它字元。返回指向s的指標。

舉例:

// strlwr.c

#include 

#include 

main()

strupr

原型:extern char *strupr(char *s);

用法:#include

功能:將字串s轉換為大寫形式

說明:只轉換s中出現的小寫字母,不改變其它字元。返回指向s的指標。

舉例:

// strupr.c

#include 

#include 

main()

常用字串函式

獲取檔案目錄 dirname c test web home.php 將字串填充到指定長度 str pad str,10,str pad both 重複指定字串 str repeat 4 按照指定長度將字串分割到陣列中 str split str,4 字串反轉 strrev str 大小寫轉換 st...

常用字串函式

strlen string 得到字串長度 strpos string,search offset 在指定字串中查詢目標字串第一次出現的位置 stripos string,search offset 忽略大小寫的去查詢 strrpos string,search offset 在指定字串中查詢目標字串...

mysql常用字串 MYSQL常用字串函式寶典

mysql常用字串函式 想更進一步加強自己在查詢語句方面的能力,需要掌握常用函式。字串函式 1 concat s1,s2,sn 將s1,s2,sn串聯成乙個字串。exp root test 14 43 desc t1 field type null key default extra id int ...