字串的一些函式

2021-10-01 17:16:57 字數 890 閱讀 6349

單字元超作

獲取字串長度strlen(strsrc)。

char str3 = "hello";

int len;

len = strlen( str3 );

printf("strlen = %d ", len );

它純在這一點侷限 ,但字元陣列中有 /0 時,字元長度返回值是錯誤的。

倆個字元超作

複製字串超作函式 strcpy( strdet , strsrc );將strscr複製到strdet中。

char str1 = "compare"; 

char str2 = "compare";

printf(strcpy( str1 , str2 ));

對應的複製指定長度的字串 strncpy( strdet , strsrc , n ); n表示複製長度。長度之後的字串保持原樣。

char str1 = "hello";

char str2 = "world";

printf(strncpy( str1 , str2 ,3 ));

附加字串 strcat (str1 ,str2 ); 將str2 連線在 str1 後面。

查詢字串

strchr(str1, str2) 在字串中查詢指定字元

strrchr(p, c) 在字串中反向查詢

自己測試 結果列印的東西很奇怪,具體還要在琢磨一下。

比較字串

strcmp(p, p1) 比較字串

strcasecmp忽略大小寫比較字串

strncmp(p, p1, n) 比較指定長度字元

返回值為 0 證明比較部分一樣。

一些字串函式

1.right location,somenumber left location,somenumber select right location,2 from my contacts 返回location列中所有右數兩個字元 select left location,2 from my cont...

一些關於字串的函式

函式名 stpcpy 功 能 拷貝乙個字串到另乙個 用 法 char stpcpy char destin,char source 程式例 include include int main void 函式名 strcat 功 能 字串拼接函式 用 法 char strcat char destin,...

一些簡單的字串函式

在編寫程式的時候,經常需要對字元和字串進行操作,如轉換字元的大小寫 求字串長度等等,這些都可以使用字元函式和字串函式來處理。c語言標準函式庫為其提供了一系列處理函式。在編寫函式的過程中,合理 有效地使用這些字串函式,可以提高程式設計效率,同時也可以提高程式效能。這裡介紹一些常用的字串處理函式。一 s...